i have a listview with a picture and some text. I set a onclicklistener so that when the user clicks the imageview the bitmap of that imageview should change. what happenes it the imageview just disappears.
holder.imageview.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
holder.imageview.setImageBitmap( bitmap);
}
});
You wrote in comments that you are using:
BitmapFactory.decodeResource(null, R.drawable.myicon);
which is wrong, first parameter is null, use the following instead:
Context context = getApplicationContext().getResources();
...
BitmapFactory.decodeResource(context.getResources(), R.drawable.myicon);
OR
BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.myicon);
and then notify the ListView
adapter that image has changed:
listViewAdapter.notifyDataSetChanged();
try this:
ImageButton ib = (ImageButton) findViewById(R.id.imgbtn);
ImageView imgv = holder.(ImageView) findViewById(R.id.imagev);
imgv.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
imgv.setImageBitmap(bm);
adapter.notifyDataSetChanged();
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.