I am doing some Android programming, and I had a question about onClickListeners (android is done in Java).

I am dynamically creating table rows as I walk down Cursor results of an SQL query and adding them to the table. Right before I add the table to the row, I am trying to set a listener for EACH row, and the action will be based on the row. The problem is that when the action is triggered, 'rowCount' keeps evaluating to the total # of Rows, instead of what it was at the time I created the Listener. Any way to get this to work?

System.out.println("On Row "+RowCount);
trA[RowCount] = new TableRow(this);


new OnClickListener() {
public void onClick(View v) {
// SetValues(trA[RowCount].getId());



//Add the Row to the table