开发者

Get child view from a ListView within a ListActivity

开发者 https://www.devze.com 2023-02-07 23:49 出处:网络
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 c

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 incor开发者_Python百科rectly?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消