HOW TO CREATE DYNAMICALLY IMAGE BUTTON WITH CLICK EVENT IN ANDROID?

Elena Glibart

Total Post:42

Points:296
Posted by  Elena Glibart
 963  View(s)
Ratings:
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.

  1. Anurag Sharma

    Post:40

    Points:280
    Re: How to create dynamically image button with click event in android?

    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();
        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!