How to change image in custom row_item inside itemClickListener?

非 Y 不嫁゛ 提交于 2020-01-30 12:01:09

问题


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

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

  @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

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

回答1:


Adapters are the link between your data the Views that displays that data. So if you need your views to be changed you should update your data first then as soon as you modified the data Call notifyDataSetChanged() on your Adapter object and your views will be updated.




回答2:


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



来源:https://stackoverflow.com/questions/57548310/how-to-change-image-in-custom-row-item-inside-itemclicklistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!