I believe you need to wear one AdapterView.OnItemClickListener
in his GridView
, so can be notified when an item of your GridView
is selected.
The code would be 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 have greatly simplified the code (leaving only the most important code), omitting some methods and code that need to be implemented. But I recommend reading the documentation on the GridView
, and a how to link the data to a AdapterView
, the class AdapterView.OnItemClickListener
and the class itself AdapterView
that has many others Listeners
that may be useful.
Is wearing a
Adapter
correct?– Wakim