I’m creating tablerows programmatically, and I’m trying to implement an OnClickListener:
final TableRow tr = new TableRow(this);
tr.setId(tourney.getColumnIndex("_id"));
tr.setClickable(true);
tr.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
v.setBackgroundColor(Color.GRAY);
System.out.println("Row clicked: " + v.getId());
}
});
But everytime I click on the row, I get a value of -1. Why am I not getting the id that I set?
The reason why I was getting -1 on getId was because of this line:
“_id” was not a part of the query, so I was not getting the column index. Even then, it wasn’t the value I really wanted, but this fixed my issue: