0
我有一個ViewPager,它包含一個GridView。這是PagerAdaper的instantiateItem
方法:Android - 沒有調用GridView onItemClick回調當GridView在ViewPager中時
@Override
public Object instantiateItem(ViewGroup container, int position) {
View page = inflater.inflate(R.layout.emoticon_grid, null);
GridView grid = (GridView) page.findViewById(R.id.emoticon_grid);
grid.setAdapter(new EmoticonListAdapter(context, list, position));
container.addView(page);
grid.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if(listener != null) {
Emoticon selectedEmoticon = (Emoticon) arg0.getAdapter().getItem(arg2);
listener.emoticonSelected(selectedEmoticon);
}
}
});
return page;
}
從我可以告訴,加上固有的點擊美景(如按鈕)GridView的當其他人都遇到過類似的問題。但我只使用一個ImageView的
public View getView(int position, View convertView, ViewGroup parent) {
Emoticon emoticon = emoticons[position];
if(convertView == null) {
convertView = new ImageView(context);
}
((ImageView) convertView).setImageResource(emoticon.ResourceId);
return convertView;
}
添加調試日誌,並設置在onItemClickMethod斷點後,回調是永遠不會獲取調用。