如何在itemClickListener内的自定义row_item中更改图像? [英] How to change image in custom row_item inside itemClickListener?

查看:129
本文介绍了如何在itemClickListener内的自定义row_item中更改图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

屏幕截图此图解释了我的问题 " https://i.stack.imgur.com/FhUH8.png "

Screenshot This image explains my question "https://i.stack.imgur.com/FhUH8.png"

活动 Display.java

Activity Display.java

lv.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() 
{
    @Override
    public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
        int checked_Items = lv.getCheckedItemCount();
        mode.setTitle(checked_Items + " Selected");
        //list_item.add(id);
        if (checked) {
            [Here][1] I want to get reference of imgView contained in custom_list.xml
            list_item.add(id);    
        } else {
            list_item.remove(id);
        }

MyAdapter.java

MyAdapter.java

  @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        inflater=(LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.custom_listview,null);
        //TextView id =convertView.findViewById(R.id.ID_c);
        TextView Name =convertView.findViewById(R.id.name_c);
        TextView Roll =convertView.findViewById(R.id.roll_c);
        ImageView imageView = convertView.findViewById(R.id.img_c);
         imageView2 = convertView.findViewById(R.id.img_2);

custom_listview.xml

custom_listview.xml

<ImageView
    android:id="@+id/img_2"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_alignParentLeft="true"
    android:src="@drawable/popup_cancel_icon"/>

推荐答案

只需从数据中设置imageView,然后在适配器中调用notifyDataSetChanged()即可更新视图并显示新图像.

just set your imageView from your data and then call notifyDataSetChanged() in your adapter to update your view and display the new image.

这篇关于如何在itemClickListener内的自定义row_item中更改图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆