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

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

问题描述

我有一个由 Adapter 填充的 Gridview,它返回 LinearLayouts,每个都包含一个 ImageButton 和 TextView.

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

在适配器中,我将 onClick 和 onLongClick 事件绑定到 ImageButton.

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

我正在尝试将 OnItemClickListener 绑定到 gridview,但我不知道为什么 onItemclicked 从未启动.

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

这是我第 6 个小时什么都没做.

It's my 6th hour without anything.

顺便说一下;OnItemSelectListener 在网格上完美运行.

By the way; OnItemSelectListener working perfectly on the Grid.

我正在检查是否有代码不小心处理了 onItemClicked 但还没有捕获.

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

伙计们,我需要帮助.

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();
    }
}

推荐答案

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

Do not use clickable objects in the grid. In that case Android cannot handle the click event of GridView.

相反,使用一些东西来显示类似的用户界面视图.然后处理该对象的点击操作.

Instead, use something to show a similar user interface view. Then handle that object's click actions.

不要:Button 放在 GridView 中以执行一些点击操作.

Don't: put Button in the GridView to perform some click actions.

做:放置一个 ImageView 而不是 ImageButton 并处理 ImageView 的点击事件.

Do: put an ImageView instead of ImageButton and handle ImageView's click events.

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

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