Sure. It's shown below, a little modified for your case:
public class FiftyButtonActivity extends Activity {
// Button IDs
final static private int[] buttonIDs = {
R.id.BID1,
R.id.BID2 ,
...
R.id.BID50
};
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for( int index = 0 ; index < buttonIDs.length ; index++ ) {
Button button = (Button) findViewById( buttonIDs
[index] );
button.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
doWork( buttonIDs[index] );
}
});
}
void doWork( int id ) {
switch( id ) {
case R.id.BID1:
// special work for this button
break;
case R.id.BID2:
// special work for this button
break;
....
case R.id.BID50:
// special work for this button
break;
default:
// error case
}
}
}
On Aug 17, 11:32 pm, Bhavya <[email protected]> wrote:
> Thanks all for ur feedback's.
> Making my question simple "Can I map the onClick() event of each
> buttons to a launch of an activity, instead of Java in an XML"
> Some what like what Struts framework does in Web Application.
>
> @Bret: Can u share the code u mentioned.
>
> ./bhavya
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en