Get child view from a ListView within a ListActivity

1.9k views Asked by At

I have a ListActivity with a ListView populated onStart with data from a database. Each row is a custom view. After the ListView is populated I want to select a specific row and edit it (for example change the background).

If I try getListView().getChildCount() after it is populated I always get 0. Am I misunderstanding how getChildCount works or have I used it incorrectly?

1

There are 1 answers

2
runor49 On BEST ANSWER

I'm not exactly sure what you are trying to do, but if you want to select a row (click a row) and change the background color, this could work:

getListView().setOnItemClickListener(new OnItemClickListener(){

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {
                        arg1.setBackgroundColor(Color.parseColor("#444444"));

                    }});

If you are trying to do programmatically on population, you should override your list adapter and do it in there.