Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I associate checkbox for each items of custom listview which extends BaseAdapter
    text
    copied!<p>I have Custom List to display image with it's name like below...</p> <pre><code> public class LazyAdapter extends BaseAdapter { private Activity activity; private String[] data; private static LayoutInflater inflater=null; public ImageLoader imageLoader; public LazyAdapter(Activity a, String[] d) { activity = a; data=d; inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageLoader=new ImageLoader(activity.getApplicationContext()); } public int getCount() { return data.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public static class ViewHolder{ public TextView text; public ImageView image,yesimage; } public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; ViewHolder holder; if(convertView==null){ vi = inflater.inflate(R.layout.item, null); holder=new ViewHolder(); holder.text=(TextView)vi.findViewById(R.id.text);; holder.image=(ImageView)vi.findViewById(R.id.image); holder.yesimage=(ImageView)vi.findViewById(R.id.selectedyes); vi.setTag(holder); } else holder=(ViewHolder)vi.getTag(); holder.text.setText("item "+position); holder.image.setTag(data[position]); holder.yesimage.setTag(data[position]); imageLoader.DisplayImage(data[position], activity, holder.image,holder.yesimage); return vi; } } </code></pre> <p>for this list I'm trying to set,</p> <pre><code> list=(ListView)findViewById(R.id.list); adapter=new LazyAdapter(this, mStrings);//mstrings is array list.setAdapter(adapter); list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); </code></pre> <p>where as I'm able to get all checked list items using,</p> <pre><code> list.setOnItemClickListener(new OnItemClickListener(){ TextView selected=(TextView)findViewById(R.id.selected); final ArrayList&lt;String&gt; years = new ArrayList&lt;String&gt;(); @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { SparseBooleanArray checked = list.getCheckedItemPositions(); if(checked.get(arg2)) { years.add(""+mStrings[arg2]+"\n"); } else { years.remove(" "+mStrings[arg2]+"\n"); } if(years.size()!=0) selected.setText(years.toString()); else selected.setText("You Have Nothing in Cart"); }}); </code></pre> <p>but nothing indicates in list that the selected item is checked, it just considers clicked item as selected,Here I cannot use,</p> <pre><code> list.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_multiple_choice, mStrings)); list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); </code></pre> <p>Because my list Extends BaseAdapter,</p> <p>I want to put the checkbox for every row in the list, to ensure that the item is checked once I check that list item, how can I do that...? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload