Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to use same caption for multiple buttons.
 what i exactly want is that i will create multiple buttons with same caption and add these all buttons to same event listener class.
how will i know from which button event has been triggered?


What I have tried:

i haven't tried anything. I'm confused from where should i start.
Posted
Updated 31-Mar-19 22:11pm
Comments
Mohibur Rashid 31-Mar-19 18:29pm    
You can call same common function but different event handler.

1 solution

When you create the button you should keep its reference somewhere so you can test which button it is in the handler.
Java
Button FoodButton = new Button("DoIt")
Button DrinkButton = new Button("DoIt")
 
Share this answer
 
Comments
Raj Swami 1-Apr-19 6:45am    
I'm developing a medical software.. where i will show all list of medicines and i will give option to add the item to cart from the list... so there will be list of thousands product so i have to create thousands of handlers..it will make my code very complicated. please give another solution
Richard MacCutchan 1-Apr-19 7:15am    
You do not need to create thousands of handlers; your design is wrong.

If you are displaying lists of medicines for the user to choose then you should be using a ListBox. You first ask some relevant questions and from the results build a list of the appropriate medicines. The user can then select the ones they need and click a single button to proceed with the order.
Raj Swami 1-Apr-19 10:44am    
ok i will try. thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900