如何访问列表视图中的特定项目?

发布于 2024-11-30 15:43:17 字数 627 浏览 1 评论 0原文

我在每个列表视图中使用名为 row_layout.xml 的布局,以便列表视图中的每个项目都包含一个文本视图和一个可绘制对象。我希望能够单击一个项目并更改该特定项目内的可绘制对象。我该怎么做呢?

例如,

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();

        }
    });

这不会切换我想要的选中文本视图,它只会从上到下检查框,因为视图 ​​arg1 是整个列表视图,而不是项目本身。

I am 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃安静 2024-12-07 15:43:17

您应该重写 ListActivity 的 protected void onListItemClick(ListView l, View v, int position, long id)。这将为您提供用户单击的列表中项目的位置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文