Select multiple items from listview and change color of selected item only

后端 未结 7 688
面向向阳花
面向向阳花 2020-12-30 13:40

I want to make a view where I can select multiple items from listview and also side by side am changing the color of selected list item and saving that item into my arraylis

7条回答
  •  别那么骄傲
    2020-12-30 14:11

    Whatever you try to do with ConvertView in itemClick listener it will reflect in some other class, to avoid that you need to set the background for corresponding view holder , i show up some sample which works fine for me,

    public View getView(final int position, View convertView, ViewGroup parent) {
             System.gc();
             final ViewHolder holder;
    
             if (convertView == null) {
                 convertView = mInflater.inflate(R.layout.albumlist, null);
                 holder = new ViewHolder();
                 holder.albumName = (TextView) convertView.findViewById(R.id.albumDetails);
    
                 convertView.setTag(holder);
             }
             else {
                 holder = (ViewHolder) convertView.getTag();
             }
    
    
             holder.albumName.setText(albumData[position][0]);
    
             holder.albumName.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {
                     holder.albumName.setBackgroundColor(R.color.black);
    
    
                 }});
    
             return convertView;
     }
    
         class ViewHolder {
    
             TextView albumName;
    
    
         }
    

    sample o/p enter image description here

提交回复
热议问题