-3

How can i set my own option on view? I need something like this:

TableRow tblr_data = new TableRow(this);
tblr_data.setOption("my_option", "my_option_value"); //there is no such method

Another words i need to add custom option to table row (custom id for example) and then use it in onclick handler.

fiction
  • 566
  • 1
  • 6
  • 21

1 Answers1

2

If I understand your question correctly, you could use the setTag(int key, Object tag) method.

//member variable
private int MY_OPTION = 1;

//when creating your tablerow
tblr_data.setTag(MY_OPTION, "my_option_value");

then in your onClickListener, you can just fetch that value again by calling

String value = (String)tblr_data.getTag(MY_OPTION);

See this accepted answer for more on the get/setTag() method.

What is the main purpose of setTag() getTag() methods of View?

Community
  • 1
  • 1
SnyersK
  • 1,296
  • 8
  • 23