How to create dynamically image button with click event in android?

Total Post:42

Points:296
 1303  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. 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();
        }

      Modified On Apr-06-2018 05:08:57 AM

Answer