Take the 2-minute tour ×

I have listview which has 5000 items. I want to get item of listview at some position and do smth with it, I call getListView().getChildAt(1) method and it returns null.

protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub

cur = ItemDao.getItemsCursor();
column_names = new String[] { ItemDao.NAME, ItemDao.MEASUREUNIT, ItemDao.REM };
columns = new int[] { R.id.item_name, R.id.item_measureunit, R.id.item_rem };

scadap = new SimpleCursorAdapter(this, R.layout.list_items, cur, column_names, columns, 0);
ListView list = getListView();



share|improve this question
can you post your code so we better understand the issue? at first look seems you don't have values in your list. –  cosmincalistru Aug 9 '12 at 7:25
@cosmincalistru added code, my list view has items, I checked –  Vahan Aug 9 '12 at 7:28
Please see my updated answer. –  Korhan Ozturk Aug 9 '12 at 7:51
add comment

2 Answers

up vote 1 down vote accepted

The problem might be due to trying to retrieve list view's child item on onCreate() where any view-related methods will return null (or empty) because the list has not been rendered yet.

One solution could be to get your listview and set the adapters and listeners in onPostCreate() method.

share|improve this answer
I write this in onPostCreate() and get the same result –  Vahan Aug 9 '12 at 8:07
add comment

Try to use OnItemClickListener() for getting selected item

listView.setOnItemClickListener(new OnItemClickListener() {

        long arg3) {
    // TODO Auto-generated method stub
    String  getSelectedItemOfList = yourList.get(pos); // here you can get selected item.

Hope this helps.

share|improve this answer
What if I want to cheange item not on click, for example I want tochange it when some condition becomes true –  Vahan Aug 9 '12 at 8:13
@Vahan You have to change/modify list or what? If it is so then you can use notifyDatasetChange() method for your adapter. –  Akshay Aug 9 '12 at 8:29
modify element of list, for example list items has boolean property isnew and I qant to show the new ones with other color –  Vahan Aug 10 '12 at 7:46
add comment

Your Answer


