silverburgh
silverburgh

Reputation: 9579

How can I find out the row /column of a view inside table layout

Suppose I have a view inside TableLayout, like this:

TableLayout tableLayout;
View view = (View)tableLayout.findViewById(R.id.control);

How can I find out the view's row/column within the TableLayout?

Upvotes: 2

Views: 1946

Answers (3)

lini sax
lini sax

Reputation: 921

While designing the tablerow in code, you can use setTag() to set it to row number. Later it can be retrieved by tableRow.getTag(). In xml you may use android:tag="2".

Upvotes: 0

3c71
3c71

Reputation: 4511

There is no such getIndexOfChild(view) in TableLayout class, but a indexOfChild()!

Upvotes: 0

Cheryl Simon
Cheryl Simon

Reputation: 46844

A view that is within a TableRow should have TableRow.LayoutParams as its LayoutParams. From that you can get the layout_column.

The row seems to be a bit harder. I'd expect the TableLayout.LayoutParams (gotten from the TableRow) to have that information, but it doesn't seem to. You could try using tableLayout.getIndexOfChild(rowView).

Upvotes: 2

Related Questions