I am dynamically creating a table of ImageButton, I would like to have setPressed to true for the image button. when it’s clicked by the user. Since I have created the buttons dynamically, how do I setPressed using onClickListener?
{
ImageButton b = new ImageButton(this);
b.setLayoutParams(new TableRow.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
b.setBackgroundResource(R.drawable.happy);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
onClickListenerForTag("tagStr");
}
}
}
private void onClickListenerForTag(final String tagStr) {
assert (tagStr != null);
mTagStr = tagStr;
//need to call setPressed(true) here ?
}
The
Viewbeing passed in to the handler is the button instance. Cast theButtonand call the method.