开发者

How do I access a specific item inside of a listview?

开发者 https://www.devze.com 2023-03-29 04:19 出处:网络
I a开发者_开发知识库m using a layout called row_layout.xml inside every listview so that each item inside the listview contains a textview and a drawable. I want to be able to click an item and change

I a开发者_开发知识库m using a layout called row_layout.xml inside every listview so that each item inside the listview contains a textview and a drawable. I want to be able to click an item and change the drawable inside that specific item. How do I go about doing this?

eg

final ListView lv2 = (ListView) findViewById(R.id.trackingmelistview);
    lv2.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            CheckedTextView checkedTextView = (CheckedTextView)arg1.findViewById(R.id.checkedTextView1);

            checkedTextView.toggle();

        }
    });

This does not toggle the checkedtext view that I want, it would just check the boxes from top to bottom because the view arg1 is the whole list view and not the item itself.


You should override protected void onListItemClick(ListView l, View v, int position, long id) of the ListActivity. That will give you the position of the item in the list that the user clicked on.

0

精彩评论

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