0

Iam newbie to android. I had created an application which contains a grid with single column and multiple rows. I had implemented onItemClick method. I need to identify which row has been selected. I cant achieve it through getId() as it returns only same id for all rows. Is there any way to achieve this?

Thanks in Advance

1 Answers1

2

You have an argument in the OnItemClickListener which correspond to the item position.

gridView.setOnItemClickListener(new OnItemClickListener()
{
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
    {
        //Selected item is at index "position".
    }
});

If you want the exact row of the selection, you can use your columns number, with something like

int row = position / columnsNumber
Aerilys
  • 1,628
  • 1
  • 16
  • 22
  • ya its working. but for dynamic grid how can i achieve this?? –  Jun 11 '13 at 09:25
  • What do you call dynamic grid? Even if you want to change the number of columns, I guess you still have a reference to this number somewhere. – Aerilys Jun 11 '13 at 09:29