I believe you need to use AdapterView.OnItemClickListener
in your GridView
, so you can be notified when an item of your GridView
is selected.
The code would look something like:
public class MyActivity extends Activity {
ListAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(...);
mAdapter = new MyAdapter(); // Inicialize seu Adapter
GridView gv = (GridView) findViewById(...); // Recupera o GridView
gv.setAdapter(mAdapter);
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
Object obj = mAdapter.getItem(position);
// Usar o objeto relativo aquela célula
}
});
}
}
public class MyAdapter extends BaseAdapter {
List<Object> mItems = new ArrayList<Object>();
// Demais metodos necessário
public Object getItem(int position) {
return mItems.get(position);
}
}
Of course I simplified the code a lot (leaving only the most important code), omitting some methods and code that need to be implemented. But I recommend reading the GridView
documentation, and a Tutorial on how to bind data to a AdapterView
, class AdapterView.OnItemClickListener
and the class itself AdapterView
that has many other Listeners
that may be useful.