具有OnItemClickListener的ListView [英] ListView with OnItemClickListener

查看:47
本文介绍了具有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天全站免登陆