ListView with multiple choice

Hi Guys!!
Today i am sharing the code of the multiple choice option select in list view.
ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list. 

For more details about the List View visit the Android Developer site List View.

Lets Start the coding now.



package com.sunil.listview;

import android.os.Bundle;
import android.util.SparseBooleanArray; 
import android.view.View;
import android.widget.ArrayAdapter; 
import android.widget.Button;
import android.widget.ListView;
 import android.widget.Toast;
public class MainActivity extends Activity {
    ListView myList;
    Button getChoice;
   String[] listContent = {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        myList = (ListView)findViewById(;
        getChoice = (Button)findViewById(;
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, listContent);
        getChoice.setOnClickListener(new Button.OnClickListener(){

            public void onClick(View v) {
                String selected = "";
                int cntChoice = myList.getCount();
                SparseBooleanArray sparseBooleanArray = myList.getCheckedItemPositions();
                for(int i = 0; i < cntChoice; i++){ 
                    if(sparseBooleanArray.get(i)) { 
                        selected += myList.getItemAtPosition(i).toString() + "\n";
                Toast.makeText(MainActivity.this, selected, Toast.LENGTH_LONG).show();

Please download the source code ListView with multiple choice

 Cheers Guys!!


Debug Database in Android

In my last tutorial, we have learned how we can use persistence database in android. We also understood which database wrapper we can use...

Contact Me


Email *

Message *