为 ExpandableListView 设置 onChildClickListener 时出现问题

发布于 2024-11-17 07:07:35 字数 569 浏览 8 评论 0原文

我在让可扩展列表视图的点击侦听器正常工作时遇到问题。我是否正确执行此操作?

代码:

elv = getExpandableListView();

// Set up the adapter
mAdapter = new MyExpandableListAdapter();
elv.setAdapter(mAdapter);

elv.setOnChildClickListener(new OnChildClickListener() {

        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            Toast.makeText(getApplicationContext(), "click", Toast.LENGTH_SHORT);
            v.setBackgroundColor(0x000000);
            return false;
        }
    });

I am having a problem getting my click listener for the expandable list view to work. Am I implementing this correctly?

Code:

elv = getExpandableListView();

// Set up the adapter
mAdapter = new MyExpandableListAdapter();
elv.setAdapter(mAdapter);

elv.setOnChildClickListener(new OnChildClickListener() {

        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            Toast.makeText(getApplicationContext(), "click", Toast.LENGTH_SHORT);
            v.setBackgroundColor(0x000000);
            return false;
        }
    });

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

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

发布评论

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

评论(1

长不大的小祸害 2024-11-24 07:07:35

您尚未在 Toast 消息中调用 show()。因此,如果您确定它是否仅适用于 Toast 消息,那么它似乎不起作用。添加.show();在创建吐司的行的末尾,它应该显示

You haven't called show() on your Toast message. So, if you're determining if it worked merely on the Toast message, it won't seem to be working. Add .show(); at the end of the line where you create the toast and it should show up

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