GridView的OnItemClickListener不响应问题

AngleProgrammer 2009-12-15 03:46:26
直接上代码了..
public class ImageAdater extends BaseAdapter{


private Context myContext;

private String[] a = {"1","2"};

private Button the_ballView;

public ImageAdater(Context myContext)
{
this.myContext = myContext;;
}

public int getCount() {
// TODO Auto-generated method stub
return a.length;
}

public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}

public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
the_ballView = new Button(myContext);
the_ballView.setBackgroundResource(R.drawable.ball3);
the_ballView.setText(a[position]);
the_ballView.setWidth(30);
the_ballView.setHeight(30);

return the_ballView;
}
}

我在使用GridView的时候用了上面写的ImageAdater,gridView.setAdapter(myImageViewAdapter);
gridView.setOnItemClickListener(new GridView.OnItemClickListener(){

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.d("############","1111");
}


});

监听该gridView的OnItemClick事件就无响应了。
...全文
4557 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
coxfilur_2008 2012-08-06
  • 打赏
  • 举报
回复
把Button换成ImageView。
穿裤衩闯天下 2012-08-06
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]

GridView设置android:descendantFocusability="blocksDescendants"
[/Quote]
这个设置了还是没有反应啊,是不是其他地方还要设置呢?
vendor 2012-08-06
  • 打赏
  • 举报
回复
这个问题android普遍存在 就是一个焦点占据的问题 你直接把button换掉 换成ImageView最简单了
附上新手交流群:今天刚刚创建254202293
jiangyue2780 2012-06-11
  • 打赏
  • 举报
回复
GridView设置android:descendantFocusability="blocksDescendants"
jefferyyangkai 2012-06-11
  • 打赏
  • 举报
回复
2、7楼说得对,解决办法就是给button设置监听器
TediousHua 2012-06-09
  • 打赏
  • 举报
回复
好文,checkbox控件也会拦截点击事件
dengyiming 2012-05-18
  • 打赏
  • 举报
回复
设置为setFocusable(true)
haoanbang 2012-05-18
  • 打赏
  • 举报
回复
the_ballView.setClickable(false);
CallMe 2012-04-17
  • 打赏
  • 举报
回复
gridview中有节点是xxxbutton,点击事件会被xxxbutton拦截了,所以OnItemClickListener不会被callback。
mary220 2012-03-29
  • 打赏
  • 举报
回复
求解。。。。
raindrophust 2009-12-17
  • 打赏
  • 举报
回复
gridview的每个孩子是button,是不行的,你换成普通的view试一下,我感觉是button拦截了点击事件,你也可以试下给button设置监听器,button肯定可以得到点击事件。
kernll 2009-12-15
  • 打赏
  • 举报
回复
关注中

80,362

社区成员

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

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