Why does radio buttons under radiogroup1 and radiogroup2 show same ids in same activity

StackOverflow https://stackoverflow.com/questions/19128926

  •  30-06-2022
  •  | 
  •  

質問

I have settings activity under my project. And i created two RadioGroups RadioGroup1 and RadioGroup2 under it. Radio button ids under both are named as Radio0, Radio1 and Radio2. If i change id of Radio0 to rb1 under RadioGroup1 it changes Radio0 to rb1 under RadioGroup2 too. Why is that? How can i add onclick events on those this way?

役に立ちましたか?

解決

Generally speaking, all views inside the same layout file should have different ids. A good practice would even be specifying different ids for all elements across all layout files.

Ids are used to uniquely specify each element in your layout. Two elements with the same ID is always a bad idea.

In eclipse, delete the whole "id" attribute, then rewrite it. When you start writing the content of the quotation marks, write the word "id", then hit ctrl+space, then enter. a "@+id/" text should appear, then you can type the new ID and other IDs shouldn't change

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top