Find the Row Id of the selected row for a tablelayout in android

Solution1:

 

Find the row without Tag and ID.


Try this code for click in particular Table Row :
TableLayout contact_table = (TableLayout)findViewById(R.id.contact_table);
final View row=contact_table.getChildAt(i);
row.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View v){
        // TODO Auto-generated method stub
        row_id=contact_table.indexOfChild(row);
    }
});


Solution 2:


Create an int array of id say array_id[] and after setting id to table row add that id to array_id[] also like
tblrow.setId(j);
array_id[j] = j;
And in onClick method do this:
for(int i = 0;i< array_id.length;i++)
{
    TableRow tbl_row = (TableRow) findViewById(i);
    if(v.getId() == array_id[i])
    {
        /**    Perform your Operations */
    }

}
 

Comments

Popular posts from this blog

How to draw an overlay on a SurfaceView used by Camera on Android?

Android TCP Connection Chat application

Create EditText with dropdown in android