OnItemClickListener不触发在Android上的GridViewOnItemClickListener、Android、GridView

2023-09-04 23:06:54 作者:我若不坚强丶懦弱给谁看

我有一个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点击事件。

下一代 Android 系统要来了,除了兼容 刘海屏 ,还有哪些新功能

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.