android – 无法在项目单击侦听器上获取gridView
作者:互联网
我无法在Fragment中获得gridView的setOnItemClickListener.可能是什么问题?
这是我的代码::
public class MainMenuFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.main_menu_fragment, container, false);
itemsGridViewObj = (GridView) view.findViewById(R.id.itemsGridView);
itemsGridViewObj.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Log.d(TAG, "--> onItemClick listener..."); // Can not getting this method.
/*if(position == 1) {
FruitMenuFragment fruitMenuFragment = new FruitMenuFragment();
fragmentTransaction.replace(android.R.id.content, fruitMenuFragment);
fragmentTransaction.commit();
}*/
}
});
return view;
}
}`
解决方法:
您可能需要在ButtonView中设置以下内容.
机器人:可聚焦=“假”
机器人:focusableInTouchMode = “假”
见adding CheckBox to list row loses my onItemClick events?
标签:android,gridview,fragment,onitemclicklistener 来源: https://codeday.me/bug/20190715/1470022.html