Android gridView问题

时间:2014-04-28 15:19:31

标签: android gridview adapter

首先: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,为什么如果我尝试访问它们它不起作用?

1 个答案:

答案 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    
  }
});