Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For reference use the example </p> <p><a href="https://stackoverflow.com/questions/18162931/android-get-selected-item-using-checkbox-in-listview-when-i-click-a-button/18164177#18164177">Get Selected Item Using Checkbox in Listview</a></p> <p>Change your adapter class to below.</p> <p>You need to override <code>getCount</code> and use <code>SparseBooleanArray</code></p> <pre><code>private class MyCustomAdapter extends ArrayAdapter&lt;String&gt; implements CompoundButton.OnCheckedChangeListener{ ArrayList&lt;String&gt; myList; public MyCustomAdapter(Context context, int textViewResourceId, ArrayList&lt;String&gt; sList) { super(context, textViewResourceId, sList); mCheckStates = new SparseBooleanArray(sList.size()); myList= sList; } private SparseBooleanArray mCheckStates; private class ViewHolder { TextView text; CheckBox chkbox; ImageView imageview; } @Override public int getCount() { return stg1.size(); } @Override public View getView(final int position, View convertView,ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = vi.inflate(R.layout.new_search_adptr, null); holder = new ViewHolder(); holder.text = (TextView) convertView .findViewById(R.id.adapterText1); holder.chkbox = (CheckBox) convertView .findViewById(R.id.checkBox1); holder.imageview = (ImageView) convertView .findViewById(R.id.imageView1); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.chkbox.setTag(position); holder.chkbox.setChecked(mCheckStates.get(position, false)); holder.chkbox.setOnCheckedChangeListener(this); holder.text.setText(stg1.get(position).toString()); holder.imageview.setImageBitmap(arr_img.get(position)); return convertView; } public boolean isChecked(int position) { return mCheckStates.get(position, false); } public void setChecked(int position, boolean isChecked) { mCheckStates.put(position, isChecked); } public void toggle(int position) { setChecked(position, !isChecked(position)); } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mCheckStates.put((Integer) buttonView.getTag(), isChecked); } } </code></pre> <p>To get on Button click</p> <pre><code>StringBuilder result = new StringBuilder(); for(int i=0;i&lt;youradapter.mCheckStates.size();i++) { if(youradapter.mCheckStates.get(i)==true) { result.append(arr_make.get(i).toString()+" "+arr_model.get(i).toString()+" "+arr_ver.get(i).toString()); result.append("\n"); } } Toast.makeText(MainActivity.this, result, 1000).show(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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