Creating ListView with check boxes...Android
Posted
by deewangan
on Stack Overflow
See other posts from Stack Overflow
or by deewangan
Published on 2010-01-17T18:39:18Z
Indexed on
2010/05/22
23:11 UTC
Read the original article
Hit count: 383
Hello, I am trying to create a listview that has check box beside each item. (i am following a code from the book android), but i can't get it to work, every time i run it, it crashes. since i am very new to this android staff, i have no clue what to do to get it to work, any help is appreciated.the code is below. *i have created two layout files in names of list and list_item. the code for the main activity:
public class ListDemoActivity extends ListActivity {
/** Called when the activity is first created. */
String[] listItems = {"exploring", "android","list", "activities"};
private SimpleCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.lists);
//setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, listItems));
//setContentView(R.layout.lists);
Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
startManagingCursor(c);
String[] cols = new String[]{People.NAME};
int[] names = new int[]{R.id.row_tv};
adapter = new SimpleCursorAdapter(this,R.layout.list_item,c,cols,names);
this.setListAdapter(adapter);
}
}
the lists file content:
<?xml version="1.0" encoding="utf-8"?>
and the list_item file content:
<?xml version="1.0" encoding="utf-8"?>
© Stack Overflow or respective owner