Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When ever you scroll list, every time it calls its getview() method. So, if you have any checkbox or any editbox in listcell it will reinitialize it.</p> <p>My idea is to store the status (checked or unchecked) of checkbox. So here I used ArrayList first I filled it with false value then on its click event i used to store it actual status.</p> <pre><code> class MyAdapter extends BaseAdapter implements OnClickListener { private ArrayList&lt;Boolean&gt; checks=new ArrayList&lt;Boolean&gt;();//Boolean type array to manage check box private static LayoutInflater inflater=null; public MyAdapter(Context context, ArrayList&lt;HashMap&lt;String, String&gt;&gt; d) { inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); //fill with false values for (int i = 0; i &lt; d.size(); i++) { checks.add(i, false); } } public int getCount() { return data.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; if(convertView==null) vi = inflater.inflate(R.layout.&lt;your layout&gt;, null); //Checkbox is of button type----android:button="@drawable/btn_check" //make a selector xml for checkbox checkBox=(CheckBox)vi.findViewById(R.id.check_box); checkBox.setTag(Integer.valueOf(position)); checkBox.setOnClickListener(this); checkBox.setChecked(checks.get(position)); return vi; } @Override public void onClick(View v) { int viewId=v.getId(); if(viewId== R.id.check_box) { Integer index = (Integer)v.getTag(); boolean state = checks.get(index.intValue()); checks.set(index.intValue(), !state); } } } </code></pre> <p>Update: Solution 2nd: You can put a boolean variable in your ViewHolder class. This boolean variable will used to define wether item is selected or not. </p> <p>Hope this should help you. </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