24986

How to use checkbox in listview

I use a CheckBox in ListView. My adapter as below:

@Override public View getView(int position, View convertView, ViewGroup parent) { ViewTag viewTag; if(convertView == null) { convertView = myInflater.inflate(R.layout.row, null); viewTag = new ViewTag((CheckBox)convertView.findViewById(R.id.row_check)); convertView.setTag(viewTag); } else { viewTag = (ViewTag) convertView.getTag(); } } class ViewTag { CheckBox cbx; public ViewTag(CheckBox cb) { this.cbx = cb; } }

First: In ListActivity, I try to click a button to set all items checked. How to do it? Second: In ListActivity, how to get the items which were checked?

Answer1:

There are many approaches to achieve this, simplest method is create a boolean array to keep state of each row, and set state of check from this array. To get all checked items simply check the same array item value.

Answer2:

Many ways to get solution to your problem. Please check this tutorial given below, it will provide more information to get solution to your problem.

ListView Example 3 – Simple Multiple Selection Checkboxes

I hope it may help you.

Answer3:

Check this. This tutorial works for me.

Recommend

  • How to show another layout in listactivity
  • Simple Cursor Adapter and Listview
  • Android display images from url in listview
  • Android: Handle ListView Recycle
  • Android ExpandableListActivity and TabActivity in same Class
  • Arranging in order with reference to a column
  • Activity Launch timeout has expired, giving up wake lock! and timeout for HistoryRecord
  • ProGuard and HoloEverywhere: Export Signed Application Errors
  • Android: List view that loads data dynamically based on scroll position
  • Select only one radio button at a time in custom list view, android
  • ListView in the first activity, listView in the second activity; nested Json- no images in second li
  • Does LocalBroadcastManager only work in the one Activity?
  • How to import .java from another project AND package in android
  • My Simple ListView app is leaking memory. What am I doing wrong?‏
  • startactivity() not working from inner class that extends ListActivity
  • How to implement a generic activity that can be extended by normal, List and Map Activities?
  • Load balanced Fiware Orion
  • Listview with multiple strings
  • Android: How do you create an EditText field in java class
  • Express JS Display Data By ID
  • CloseOptionsMenu doesn't work?
  • Unable to resolve Static method?
  • Activity overlaying. WindowManager.LayoutParams
  • NSIS decompiler
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • jquery mobile loadPage not working
  • align graphs with different xlab
  • Unanticipated behavior
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to stop GridView from loading again when I press back button?
  • unknown Exception android
  • Can't mass-assign protected attributes when import data from csv file
  • failed to connect to specific WiFi in android programmatically
  • Unable to use reactive element in my shiny app
  • How can I use threading to 'tick' a timer to be accessed by other threads?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize