How do I get the tag of a button from an inflated Android table?

Go To StackoverFlow.com

0

How do I get the tag of a button from an inflated table? I have the following code so far, now how do I get the tag from a button when I press a button?

TableLayout table = (TableLayout)findViewById(R.id.scheduleTable);
for (int i = 0; i < jlen; i++) { 

    // Inflate
    TableRow row = (TableRow)LayoutInflater.from(UpdateScheduleActivity.this).inflate(R.layout.schedulerow, null);
    ((TextView)row.findViewById(R.id.attr_day)).setText(json_schedule.getString(KEY_DOW));
    ((TextView)row.findViewById(R.id.attr_start)).setText(json_schedule.getString(KEY_START));
    ((TextView)row.findViewById(R.id.attr_stop)).setText(json_schedule.getString(KEY_STOP));
    ((Button)row.findViewById(R.id.btnRemove)).setTag(sid);
    table.addView(row);

}
table.requestLayout(); 
2012-04-03 23:43
by user1201347


1

in your case

btn = (Button)**row**.findViewById(R.id.btnRemove);

hope this will help you

2012-04-04 09:51
by MAC


0

You should get a reference to the button in your onItemClick or onClickListener, from there just use view.getTag()

2012-04-03 23:48
by ByteMe


0

As ByteMe said, you need to set onClickListener for your button. Something like that may work:

((Button)row.findViewById(R.id.btnRemove)).setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        ((Button) v).getTag();
        // Do whatever you like when the button is pressed.
    }
 });
2012-04-04 00:12
by ecem