---
title: "How to create dynamically image button with click event in android?"  
description: "How to create dynamically image button with click event in android?"  
author: "Elena Glibart"  
published: 2014-11-07  
updated: 2014-11-07  
canonical: https://www.mindstick.com/forum/2538/how-to-create-dynamically-image-button-with-click-event-in-android  
category: "android"  
tags: ["android activity"]  
reading_time: 1 minute  

---

# How to create dynamically image button with click event in android?

I'm new to [android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) and I require to have a list of [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) buttons in an [activity](https://www.mindstick.com/forum/12894/how-to-force-recreation-of-activity-fragment-on-restore) 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](https://www.mindstick.com/articles/336597/introduction-of-html-tables-for-web-development) to show my data in a [grid view](https://www.mindstick.com/forum/477/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](https://www.mindstick.com/interview/985/what-are-the-approaches-that-you-will-follow-for-making-a-program-very-efficient) is.

One [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) I've faced is with the [click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social) [events](https://www.mindstick.com/blog/102/events-in-c-sharp)(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](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) out of them.

## Replies

### Reply by Anurag Sharma

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();
    }
```


---

Original Source: https://www.mindstick.com/forum/2538/how-to-create-dynamically-image-button-with-click-event-in-android

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
