get checked items from listview in android
<p>I have a dynamic listview with one text and one checkbox per line.when i click a button.,i need to get all checked item names &amp; Unchecked item names separately as arraylilst.How could i do that.Examples are much better..</p>

<p>I used..</p>

<pre><code>    SparseBooleanArray checked = mainlw.getCheckedItemPositions();

    for (int i = 0; i &lt; checked.size(); i++) {

        if(checked.valueAt(i) == true) {
            Planet tag = (Planet) mainlw.getItemAtPosition(checked.keyAt(i));

            String selectedName=tag.getName();
            Toast.makeText(getApplicationContext(), selectedName, Toast.LENGTH_SHORT).show();
        }
    }
</code></pre>
