点击ListView或GridView的item无反应问题

点击ListView的item无反应
当我点击ListView中的item时,没有反应,但item中的控件操作正常,查了很多网上的资料,了解到是button抢占了item的焦点问题,网上解决的办法基本上都是下面几种建议:

1. 如果ListView的item里面有checkbox,写了ListView的Item点击事件(setOnItemClickListener)是无反应的。

猜测原因:checkbox把焦点获取了,导致listview没有响应点击事件,

一般做法,在xml布局设置checkbox属性,其中focusable是关键:
android:focusable=”false” android:clickable=”false” android:focusableInTouchMode=”false”
 

2. 如果ListView的item里面有button,方法类似于 checkbox

3. 如果ListView的item里面有RatingBar/评分组件,利用上述的checkbox的xml属性设置是无效的。最好写个adapter,然后在adapter的getView中:
convertView = mInflater.inflate ( R.layout.list_item_text,null ); convertView.setClickable ( true ); convertView.setOnClickListener ( clickListener ); public OnClickListener myClickListener = new OnClickListener (){ public void onClick ( View v ){ //code to be written to handle the click event } };

4.在xml布局文件中所设置的:android:clickable="false"也是个关键。当为true时item即可被点击,有点击效果,可以试试。。

 

尽管我这么设置后,但结果仍然不理想,没出现想要的结果,最后,在网上查到资料,给我解决了问题,现将网上的资料写在下边:

Android ListView xml配置
<ListView android:id=”@+id/locallist_lv” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:layout_above=”@id/btm_menu” android:layout_below=”@id/top_menu”           android:divider=”@drawable/song_item_line” item之间的分割线 android:cacheColorHint=”#00000000″系统切换item时的缓存色 android:scrollbars=”none”不显示滚动条       android:listSelector=”#00000000″/>选中时背景色
ListView遇到的两个问题 List集合的排序

1. 将ListView的背景色设置为白色,ListIView控件上下滑动时,背景就会变为黑色,但是图片会正常显示,这怎么解决呢?网上搜了一下,

如果大家在非黑色背景下使用ListView控件时,Android默认可能在滚动ListView时这个列表控件的背景突然变成黑色。这样可能导致程序的黑色的背景和主程序的主题既不协调。解决的方法Google在设计Android时也考虑了,在Layout的ListView中加入 android:cacheColorHint=”#00000000″ 的属性即可,或者是调用ListView的setCacheColorHint(0);方法。

2. 在ListView的item项里使用CheckBox或者Button时,OnItemClickListener无响应的问题

在Android软件设计与实现中我们通常都会使用到ListView这个控件,系统有一些预置的Adapter可以使用,例如SimpleAdapter和ArrayAdapter,但是总是会有一些情况我们需要通过自定义ListView来实现一些效果,那么在这个时候,我们通常会碰到自定义ListView无法选中整个ListViewItem的情况,也就是无法响应ListView的onItemClickListener中的onItemClick()方法,之后自己查看了一下ViewGroup的源码,发现了以下的一段常量声明:

/**

* This view will get focus before any of its descendants.

转载于:https://my.oschina.net/QQXX/blog/114452

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值