我对Android开发相当新,但是我在尝试使我的listview项目打开一个活动但是根据项目具有不同的drawable时遇到了一些麻烦。无论如何,view.getContext()都附加了一个特定的drawable。 这是我的listview类:
lv.setOnItemClickListener (new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, bring up MockClass.class
if(position == 1)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 2)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 3)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 4)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 5)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 6)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 7)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 8)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 9)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
if(position == 10)
{
Intent myIntent = new Intent(view.getContext(), MockClass.class);
startActivityForResult(myIntent, 0);
}
答案 0 :(得分:0)
您应该在intent对象上使用putExtra之类的Intent附加功能。现在你可以直接传递一个Bitmap,但我会反对它。您应该获得要传递给下一个活动的图像的路径,并将其作为额外活动传递。在你的其他活动中,你应该使用getIntent()。getStringExtra(“key”)拉出额外的活动并使用该路径加载你的Drawable。