[英]change imageview bitmap in listview
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. 我设置了一个onclicklistener,以便当用户单击imageview时,该imageview的位图应更改。 what happenes it the imageview just disappears. 发生了什么,imageview才消失。
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: 这是错误的,第一个参数为null,请改用以下内容:
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: 然后通知ListView
适配器该图像已更改:
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();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.