Android 的ListView点击无效

bluehale 2017-10-06 10:14:04
ListView就放了1个ImageView, 5个Textview,用的是SimpleAdapter, 就是给ListView的Item一个点击事件,点击就是没有反应。Item布局文件XML的外层加 android:descendantFocusability="blocksDescendants", 没用;ListView的ITem下所有控件给android:focusable="false", 加了,还是没用。到底是怎么回事呢?难道是Android的Bug?ListView只能看不能点击,太奇怪了。
绑定的代码:
SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, listMessages, R.layout.layout_invites,
new String[]{"mID", "creater", "mainContent", "deadLine", "mtype", "createrLogo"},
new int[]{R.id.tv_list_type, R.id.tv_list_name, R.id.tv_list_inviteword, R.id.tv_list_invitedate, R.id.tv_list_inviteid, R.id.iv_list_logo});
lvMessage.setAdapter(adapter);
点击事件:
lvMessage.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) { //when creater click, update the message; when others click, reset the alarm
//HashMap<String,String> map=(HashMap<String,String>)lvMessage.getItemAtPosition(arg2);
//"mID", "creater", "mainContent", "deadLine", "mtype", "createrLogo"
/**
String strID = map.get("mID");
String creater=map.get("creater");
String mainContent = map.get("mainContent");
String deadLine = map.get("deadLine");
String mtype = map.get("mtype");
MessageMain messagemain = new MessageMain();
messagemain.setmID(Integer.parseInt(strID));
messagemain.setcreater(creater);
messagemain.setmainContent(mainContent);
messagemain.setdeadLine(deadLine);
**/
Intent intent = new Intent();
intent.setClass(MainActivity.this, BasicMessageContentActivity.class);

intent.putExtra("account", Parcels.wrap(account));
//intent.putExtra("messagemain", Parcels.wrap(messagemain));
startActivity(intent);
MainActivity.this.finish();
}
}); //注释掉的部分是为测试方便,取消注释还是无法点击。
...全文
234 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluehale 2017-10-12
  • 打赏
  • 举报
回复
我直接用了Looper的,原先可能是更新程序里面有点问题,谢谢各位!
cuckoochun 2017-10-11
  • 打赏
  • 举报
回复
你是怎么控制更新的 是不是更新出问题了 getview里面log看看 是不是一直在输出
bluehale 2017-10-09
  • 打赏
  • 举报
回复
ListView之外其他的Button可以正常点击,应该不是死循环的卡死;影响到焦点的属性,android:focusable="false" android:focusableInTouchMode="false" android:descendantFocusability="blocksDescendants" android:focusable="false",都用上了,还是无效。如果我将循环代码里面的While修改Looper方式,可以点击,问题是不自动更新了,不知道怎么回事,还是研究中。
大海啊全是水 2017-10-09
  • 打赏
  • 举报
回复
看看是不是父控件中有重写touchevent的方法.如onInterceptTouchEvent, onTouchEvent
金海晗 2017-10-09
  • 打赏
  • 举报
回复
可能是listview的父布局获取到了焦点,所以这个父布局内部的子布局(也就是你的listview)并没有被点击,你点的是listview的父布局,而不是它,比如一个Layout内部一个Listview,设置不当可能会捕捉到父Layout的点击事件,而非listview的点击事件
寒冰大神 2017-10-09
  • 打赏
  • 举报
回复
不会是 一直死循环给卡死了巴。
bluehale 2017-10-06
  • 打赏
  • 举报
回复
lvMessage.setClickable(true); lvMessage.setFocusable(true); 都加上了,还是一样。刚才多次连续点击,更诡异的事情出现了,点击几十次居然有一次可以点击成功,哪位碰到过这种现象吗?另外,我后台有几个子线程一直在循环跑,就像while (IOHelper.loopjudge()) { 这样的,好几个子线程在后台一直死循环,如果有新数据,就更新页面,这个会有影响吗?

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧