OnItemClickListener不触发在Android上的GridView [英] OnItemClickListener Not Triggered on Android GridView

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

问题描述

我有一个GridView填充一个适配器返回LinearLayouts每个包含的ImageButton和TextView的。

在适配器我绑定一个onClick和onLongClick事件的ImageButton的。

我想结合OnItemClickListener到GridView,但我不知道是什么原因,该onItemclicked从未解雇了。

这是我的第6小时,没有任何东西。

顺便说一句, OnItemSelectListener在网格上正常使用。

我检查,如果某条code的意外处理onItemClicked,但没能追上呢。

我需要帮助的人。

 的GridView =(GridView控件)layoutInflater.inflate(R.layout.gridview,NULL);
gridView.setOnItemClickListener(新ItemClickListener());
。
。
。

//内部处理类
类ItemClickListener实现AdapterView.OnItemClickListener {
    @覆盖
    公共无效onItemClick(适配器视图<>适配器视图,视图中查看,INT I,长L){
        Toast.makeText(mainActivity.getApplicationContext(),查阅点击在POS+
        我,Toast.LENGTH_SHORT).show();
    }
}
 

解决方案

解决这个问题;

在网格中不要使用可点击的对象。这种情况下,Android无法处理网格的单击事件。

而不是使用的东西来表现出类似的用户界面视图。比起处理的对象点击动作。

虚假的;把网格中的按钮来执行一些点击操作。

真实的;放,而不是ImageButton的一个ImageView的和处理的ImageView点击事件。

I have a Gridview filled by an Adapter which returns LinearLayouts each contains an ImageButton and TextView.

In the adapter I am binding an onClick and onLongClick event to the ImageButton.

I am trying to bind OnItemClickListener to the gridview but I don't know why that the onItemclicked never fired up.

It's my 6th hour without anything.

By the way; OnItemSelectListener working perfectly on the Grid.

I am checking if some piece of code accidentally handles the onItemClicked but couldn't catch yet.

I need help guys.

gridView = (GridView) layoutInflater.inflate(R.layout.gridview, null);
gridView.setOnItemClickListener(new ItemClickListener());
. 
.
.

//inner handler class
class ItemClickListener implements AdapterView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Toast.makeText(mainActivity.getApplicationContext(),view + " clicked at pos " +            
        i,Toast.LENGTH_SHORT).show();
    }
}

解决方案

Solution to this question is;

Do not use clickable objects in the grid. That case Android can not handle the click event of grid.

Instead use something to show similar user interface view. Than handle that objects click actions.

false; put button in the grid to perform some click actions.

true; put an imageview instead of imagebutton and handle imageview's click events.

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

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