带有 OnItemClickListener 的 ListView [英] ListView with OnItemClickListener

查看:28
本文介绍了带有 OnItemClickListener 的 ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义 ListView 带有 RatingBarImageButton.这是我的问题:当我点击我的 ListView 时,我的 OnItemClickListener 不工作.请任何人都可以帮助我.代码:

I am using a custom ListView with RatingBar and ImageButton. Here is my problem: When I click on my ListView, my OnItemClickListener is not working. Please can any one help me. Code:

ListView lv = getListView();
setContentView(lv);
lv.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
        Toast.makeText(SuggestionActivity.this, "" + position, Toast.LENGTH_SHORT).show();
    }
});

推荐答案

虽然是一个非常古老的问题,但我仍然发布了一个答案,以便它可以帮助一些人.如果您在列表视图中使用任何布局,请使用 ...

Though a very old question, but I am still posting an answer to it so that it may help some one. If you are using any layout inside the list view then use ...

android:descendantFocusability="blocksDescendants"    

... 在列表中的第一个父布局上.这很神奇,单击不会被列表中的任何元素消耗,而是直接转到列表项.

... on the first parent layout inside the list. This works as magic the click will not be consumed by any element inside the list but will directly go to the list item.

这篇关于带有 OnItemClickListener 的 ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆