I wrote the following code but am not getting how to write OnclickListner()
method for all buttons.
public void onCreate(Bundle savedInstanceSta
If you want the buttons to do different things, you could have your Activity extend OnClickListener, set b.setOnClickListener(this)
in the loop, and add something like
@Override
public onClick(View v)
{
// get who called by
String sTag = (String) v.getTag();
if (sTag.equals("button1"))
{
//do some stuff
}
else if (sTag.equals("button2"))
{
//do some other stuff
}
// and so on
}
to handle the clicks.
And I'm editing this in here because the lack of line breaks makes comments ambiguous:
int iBtnID = v.getId();
switch (iBtnID)
{
case 101:
// do stuff;
break;
case 102:
// do other stuff
break;
// and so on
}