首先:CustomGridViewAdapter extends ArrayAdapter<Item>
守则:
ArrayList<Item> gridArray = new ArrayList<Item>();
gridArray.add(new Item(button, value[i]));
...
gridView = (GridView) findViewById(R.id.gridView);
customGridAdapter = new CustomGridViewAdapter(this, R.layout.gridview_item, gridArray);
gridView.setAdapter(customGridAdapter);
gridView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// why this part doesnt work ?
}
});
我有一个按钮的gridView,为什么如果我尝试访问它们它不起作用?
答案 0 :(得分:1)
您无法在View.onClickListener
上设置GridView
。
而是设置OnItemClickListener
gridView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//your code here
}
});