我試圖動態地實現一個Radio Group
,但我收到一個錯誤消息,說「孩子已經有一個父母先調用removeView()」。下面是我的代碼:在RadioGroup中獲取錯誤
RadioGroup rg = new RadioGroup(getContext());
RadioButton[] allSongsRadio = new RadioButton[countOfAllSongs];
ArrayList<String> allSongsInMap = new ArrayList<>(countOfAllSongs);
for(final String eachMood : allSongs.keySet()) {
for(String eachSong : allSongs.get(eachMood)) {
allSongsInMap.add(eachMood+" : "+eachSong);
}
}
for(int i=0;i<allSongsInMap.size();i++){
final String eachSong = allSongsInMap.get(i);
LinearLayout playButtonAndSeekBar = new LinearLayout(getContext());
final FloatingActionButton playButton = new FloatingActionButton(getContext());
playButton.setBackgroundTintList(ColorStateList.valueOf(Color.WHITE));
playButton.setImageResource(R.drawable.play);
playButton.setSize(FloatingActionButton.SIZE_MINI);
playButton.setId(++playButtonId);
SeekBar seekBarForEachSong = new SeekBar(getContext());
layoutDetails = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutDetails.rightMargin = 50;
seekBarForEachSong.setLayoutParams(layoutDetails);
allSongsRadio[i] = new RadioButton(getContext());
playButtonAndSeekBar.addView(allSongsRadio[i]);
playButtonAndSeekBar.addView(playButton);
playButtonAndSeekBar.addView(seekBarForEachSong);
eachSongPanel.addView(playButtonAndSeekBar);
rg.addView(allSongsRadio[i]);
dialogContainer.addView(eachSongPanel);
}
dialogContainer.addView(rg);
}
需要幫助的人。
請發佈完整的stacktrace並指出代碼中的哪一行導致錯誤。 –