Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView with Checkboxes: How to capture checked items?
    primarykey
    data
    text
    <p>I have to do a <code>ListView</code> with <code>CheckBoxes</code> and then display the checked and unchecked items when user presses the button. The problem is I don't know how to do it, I manage to display the <code>ListView</code> with the <code>CheckBox</code> with this code: </p> <pre><code>package guestCheckBox.com; import java.net.URL; import java.util.ArrayList; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; public class GuestCheckBox extends Activity { private ListView lView; ArrayList&lt;String&gt; guest= new ArrayList &lt;String&gt;(); @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); lView = (ListView) findViewById(R.id.ListView01); try{ URL url = new URL( "http://tanjungrhu.jigsy.com/files/documents/Check.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(new InputSource(url.openStream())); doc.getDocumentElement().normalize(); NodeList words = doc.getElementsByTagName("Guest"); for(int i=0;i&lt;words.getLength();i++){ Node node = words.item(i); Element fstElmnt = (Element) node; NodeList NameList = fstElmnt.getElementsByTagName("Name"); Element NameElement = (Element) NameList.item(0); NameList = NameElement.getChildNodes(); guest.add((((Node) NameList.item(0)).getNodeValue())); } } catch (Throwable t){ Toast.makeText(this, "Exeption:" + t.toString(), 2000).show(); } //Set option as Multiple Choice. So that user can able to select more the one option from list lView.setAdapter(new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_multiple_choice, guest)); lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); } } </code></pre> <p>and here my <code>main.xml</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;ListView android:id="@+id/ListView01" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; </code></pre> <p>Would somebody show me how can I do a buttons and how will I show the checked and unchecked items when the user presses that buttons? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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