Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using same id for multiple buttons

Well, I'll say it like this.

I have a table with 2 columns. The first colum has names of items, the 2nd colums contains x amount of logos/indicators (ImageButtons). Several items can have the same logo/indicators.

My question is can I assign several ImageButtons to the same id? I've tried with using android:id="@+id/logo1" on the first and then "android:id=@id/logo1" on all the following occurences. This does not seem to work however. I can probably assign each button a different id and then just assign those to the same View, but it would be so much easier if I could just repeat the same ImageButton id for all the similar logos/indicators.

like image 542
Tom Avatar asked Mar 24 '12 10:03

Tom


People also ask

Can multiple buttons have same ID?

It is not recommended to use same id for multiple elements. Replace id with class attribute. I have done a sample code that will give you a brief idea on coding part.

Can you assign an ID to a button?

An id on a <button> tag assigns an identifier to the button. The identifier must be unique across the page.

Can you have two buttons in HTML?

Complete HTML/CSS Course 2022yes, multiple submit buttons can include in the html form.

How do I make multiple buttons in HTML?

Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.


1 Answers

No, you can't use the same ids in same layout if there behavior is different.

Yes, you can use the same ids but in different layouts. In fact, it may be good practice to.

Android has some default id here they are declaring in ids.xml and reusing it in different views.

like image 174
Padma Kumar Avatar answered Nov 15 '22 03:11

Padma Kumar