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();
in your case
btn = (Button)**row**.findViewById(R.id.btnRemove);
hope this will help you
You should get a reference to the button in your onItemClick or onClickListener, from there just use view.getTag()
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.
}
});