Home > DeveloperSection > Forums > How to create dynamically image button with click event in android?
Elena Glibart
Elena Glibart

Total Post:35

Points:128
Posted on    November-07-2014 3:44 AM

 Android Android Activity 
Ratings:


 1 Reply(s)
 696  View(s)
Rate this:

I'm new to android and I require to have a list of image buttons in an activity which are created based on the data in a database. I haven't created anything like this in android before and so far I've been using HTML tables to show my data in a grid view. I'm not asking for any special code, I'm just clueless on how to implement this. I wanna know what the best approach is.

One problem I've faced is with the click events(in the way I've been doing them so far) which do not take in any EventArg, so I can't get the name of the button out of them.



Anurag Sharma
Anurag Sharma

Total Post:40

Points:280
Posted on    November-07-2014 6:02 AM

If you're sure that the OnClickListener instance is applied to a Button, then you could just cast the received view to a Button and get the text:

 public void onClick(View v) {
        
        Button b = (Button)v;
        String buttonText = b.getText().toString();
    }

Don't want to miss updates? Please click the below button!

Follow MindStick