Naina Naina - 1 year ago 84
Android Question

How to identify table row id dynamically

I have to find out table row id. For that I am writing the code

Log.e("TAG", "ID: "+match1[i].getId());
match1[i].setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {

Toast.makeText(SAXParserActivity.this, ""+tr.getId(),
Log.e("TAG", " clicked ID: "+tr.getId());
t1.addView(tr, tableRowParams);

where match1 is a text view. All is working fine but the problem is on clicking table row. For each row I am getting -1 id, but before on click the id is coming correctly. Please suggest where is the mistake, and how can I display data randomly after parsing?

Answer Source

Try this Snippet :

final View row=contact_table.getChildAt(i);
row.setOnClickListener(new OnClickListener(){
   public void onClick(View v){

where contact_table is your TableLayout object

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download