im fairly new to android development, but i’m having some trouble trying to make my listview items open up one activity but with a different drawable in it depending on the item. Is there anyway to view.getContext() with a specific drawable attached to that.
here is my listview class:
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);
}
You should be using Intent extras such as putExtra on the intent object. Now you can pass a Bitmap as an extra directly but I would advise against it. You should get the path to the image you are looking to pass to the next activity and pass that as an extra. Inside of your other activity you should pull that extra using getIntent().getStringExtra(“key”) and load your Drawable using that path.