This question already has answers here:
ChipGroup single selection
(8 answers)
Closed 3 years ago.
This is my code for setting up the chipgroup and chips inside based on list:
val chipGroup = region_list
val inflator = LayoutInflater.from(chipGroup.context)
val children = categoryList.map { categoryName ->
val chip = inflator.inflate(R.layout.region, chipGroup, false) as Chip
chip.text = categoryName.replace('_', ' ')
chip.tag = categoryName
chip.setOnCheckedChangeListener { button, isChecked ->
val s = viewModel.updateFilter(button.tag as String, isChecked)
//s is a string = {"change", "keep"}
//if s is keep that means that the same chip that was selected was pressed again, and in normal chip behaviour in android that chip would then be deselected, I don't want that
}
}
s is a string = {"change", "keep"}
if s is keep that means that the same chip that was selected was pressed again, and in normal chip behaviour in android that chip would then be deselected, I don't want that. I can't believe that android team never thought that someone would need a chipgroup where an item can't be deselected, what is the point of chips, to use it as some kind of filter to update view bellow.
Try this logic:
Your Activity:
int i=0;
String chipArr[]={"First","Second","Third","Fourth"};
int selectedChipId=0;
for (final String chipName : chipArr) {
Chip chip = (Chip) layoutInflater.inflate(R.layout.cat_chip_group_item_filter, chipGroup, false);
chip.setText(chipName);
chip.setId(i);
}
for (final String chipName : fileNameChip) {
LayoutInflater layoutInflater = getLayoutInflater();
Chip chip = (Chip) layoutInflater.inflate(R.layout.cat_chip_group_item_filter, chipGroup, false);
chip.setText(chipName);
chip.setId(i);
if (i == 0) chip.setSelected(true);
chip.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
selectedChipId=v.getId();
}
});
chipGroup.addView(chip);
i++;
}
chipGroup.setOnCheckedChangeListener(new ChipGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(ChipGroup group, int checkedId) {
Log.d(TAG, "onCheckedChanged: " + checkedId);
if (checkedId == selectedChipId) {
chip.setSelected(true);
}
}
});
Activity layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.ShowCodeActivity">
<HorizontalScrollView
android:id="#+id/horScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:scrollbars="none">
<com.google.android.material.chip.ChipGroup
android:id="#+id/chip_group_code_files"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_4dp"
android:layout_marginEnd="#dimen/margin_4dp"
app:singleLine="true"
app:singleSelection="true" />
</HorizontalScrollView>
</RelativeLayout>
Your cat_chip_group_item_filter.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="#style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Let me know if it worked for you or not as I haven't tested it!!
Related
I'm using a RecyclerView with LinearLayout Manager and Horizontal orientation.
It's to be used on a TV app, so it needs to be navigated with the dpad. But whenever I go do the end and come back it get stuck on the last one. See photo:
The selected ItemView is the first, but it won't go to the center. if you go to the right and the come back it will show fully.
the code:
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="320dp"
app:layout_constraintBottom_toTopOf="#+id/tv_mini_player_view_placeholder"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/carrier_image_card"
app:layout_constraintVertical_bias="0.10">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/margin_start_tv_home"
android:background="#null"
android:clipToPadding="false"
android:orientation="horizontal"
android:padding="#dimen/margin_medium_big"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:context=".android.screens.auth.SelectCarrierActivity"
tools:listitem="#layout/imagecardview_station" />
</androidx.core.widget.NestedScrollView>
One little thing I observed is the layout World Hits didn't adjust the label size. When selected these layouts show a description which makes the transparent grey box larger to acommodate. It's a "View.GONE" change on the description label. So the last selected layout the description disappeared but the layout didn't readjusted. The code for the View Holder part is below:
inner class StationViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val mainImageView: ImageView by lazy { itemView.findViewById<ImageView>(R.id.main_image) }
val titleView: TextView by lazy { itemView.findViewById<TextView>(R.id.title_text) }
val descriptionView: TextView by lazy { itemView.findViewById<TextView>(R.id.description_text) }
init {
val frameLayout = itemView.findViewById<FrameLayout>(R.id.frame_layout)
val cardView = itemView.findViewById<FrameLayout>(R.id.cardview)
cardView.apply {
isFocusable = true
isFocusableInTouchMode = true
onFocusChangeListener = View.OnFocusChangeListener { v, hasFocus ->
if (hasFocus) {
AbstractCardPresenter.animateScaleUp(cardView as View)
frameLayout.background = itemView.context.resources.getDrawable(R.drawable.card_border)
descriptionView.visibility = View.VISIBLE
} else {
AbstractCardPresenter.animateScaleDown(cardView as View)
frameLayout.background = null
descriptionView.visibility = View.GONE
}
}
}
itemView.onAttachStateChangeListener {
onViewAttachedToWindow {
if (adapterPosition == 0) {
cardView.requestFocus()
}
}
}
}
}
U need to get rid of NestedScrollView
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/margin_start_tv_home"
android:background="#null"
android:clipToPadding="false"
android:orientation="horizontal"
android:padding="#dimen/margin_medium_big"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:context=".android.screens.auth.SelectCarrierActivity"
tools:listitem="#layout/imagecardview_station" />
I found the offending bit of code!! I was trying to get focus on the first ViewHolder of the RecyclerView upon load. That was causing the problem. Just need to find another way to do it now! This bit of code right there:
itemView.onAttachStateChangeListener {
onViewAttachedToWindow {
if (adapterPosition == 0) {
cardView.requestFocus()
}
}
}
Is there an option to make the MaterialButtonToggleGroup have a required selected button when using app:singleSelection="true"?
When clicking to a different button works fine (all other buttons are deselected), but when you click the same (already selected) button it deselects it itself and I want to remain selected.
My example:
<com.google.android.material.button.MaterialButtonToggleGroup
android:layout_width="wrap"
android:layout_height="wrap_content"
app:singleSelection="true">
<com.google.android.material.button.MaterialButton
android:id="#+id/filterA"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/filterB"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"/>
<com.google.android.material.button.MaterialButton
android:id="#+id/filterC"
style="#style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"/>
</com.google.android.material.button.MaterialButtonToggleGroup>
You can define it in the layout using the app:selectionRequired attribute:
<com.google.android.material.button.MaterialButtonToggleGroup
app:selectionRequired="true"
app:checkedButton="#id/..."
app:singleSelection="true">
You can also use the method setSelectionRequired:
buttonGroup.setSelectionRequired(true);
Note: This requires a minimum of version 1.2.0-alpha03
I got this working with the following:
toggle_group.addOnButtonCheckedListener { group, checkedId, isChecked ->
if (group.checkedButtonId == -1) group.check(checkedId)
}
If you have singleSelection enabled, the conditional will only evaluate to true when the user has clicked on the button which is already checked, making it so no button is checked. When this happens, we just need to check the button they unchecked.
I also came across this issue and I found this is working with the app:singleSelection="true"
String selectedValue = "Male";
genderBtnToggle.addOnButtonCheckedListener(new MaterialButtonToggleGroup.OnButtonCheckedListener() {
#Override
public void onButtonChecked(MaterialButtonToggleGroup group, int checkedId, boolean isChecked) {
MaterialButton btn = genderBtnToggle.findViewById(checkedId);
if (!isChecked && btn.getText().toString().equals(selectedValue)) {
genderBtnToggle.check(checkedId);
}
if (isChecked) {
selectedValue = btn.getText().toString();
}
}
});
I also came across this issue and will be waiting for a permanent fix from google. In the meantime, I did the following to make sure that at least one button is checked.
final MaterialButtonToggleGroup tGroup = view.findViewById(R.id.toggleGroup);
final MaterialButton breast = tGroup.findViewById(R.id.breast);
final MaterialButton bottle = tGroup.findViewById(R.id.bottle);
final MaterialButton solids = tGroup.findViewById(R.id.solids);
View.OnClickListener onClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
tGroup.check(v.getId());
}
};
breast.setOnClickListener(onClickListener);
bottle.setOnClickListener(onClickListener);
solids.setOnClickListener(onClickListener);
Hope this helps.
How can I force a ChipGroup to act like a RadioGroup as in having at least one selected item always? Setting setSingleSelection(true) also adds the possibility to have nothing selected if you click twice on a Chip.
To prevent all chips from being deselected you can use the method setSelectionRequired:
chipGroup.setSelectionRequired(true)
You can also define it in the layout using the app:selectionRequired attribute:
<com.google.android.material.chip.ChipGroup
app:singleSelection="true"
app:selectionRequired="true"
app:checkedChip="#id/..."
..>
Note: This requires a minimum of version 1.2.0
EDIT
With version 1.2.0-alpha02 the old hacky solution is no longer required!
Either use the attribute app:selectionRequired="true"
<com.google.android.material.chip.ChipGroup
android:id="#+id/group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:selectionRequired="true"
app:singleSelection="true">
(...)
</com.google.android.material.chip.ChipGroup>
Or in code
// Kotlin
group.isSelectionRequired = true
// Java
group.setSelectionRequired(true);
For older versions 👇
There are two steps to achieve this
Step 1
We have this support built-in, just make sure to add app:singleSelection="true" to your ChipGroup, for example:
XML
<com.google.android.material.chip.ChipGroup
android:id="#+id/group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:singleSelection="true">
<com.google.android.material.chip.Chip
android:id="#+id/option_1"
style="#style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<com.google.android.material.chip.Chip
android:id="#+id/option_2"
style="#style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
</com.google.android.material.chip.ChipGroup>
Code
// Kotlin
group.isSingleSelection = true
// Java
group.setSingleSelection(true);
Step 2
Now to support a radio group like functionality:
var lastCheckedId = View.NO_ID
chipGroup.setOnCheckedChangeListener { group, checkedId ->
if(checkedId == View.NO_ID) {
// User tried to uncheck, make sure to keep the chip checked
group.check(lastCheckedId)
return#setOnCheckedChangeListener
}
lastCheckedId = checkedId
// New selection happened, do your logic here.
(...)
}
From the docs:
ChipGroup also supports a multiple-exclusion scope for a set of chips.
When you set the app:singleSelection attribute, checking one chip that
belongs to a chip group unchecks any previously checked chip within
the same group. The behavior mirrors that of RadioGroup.
A solution would be to preset a clicked chip and then toggling the clickable property of the chips:
chipGroup.setOnCheckedChangeListener((chipGroup, id) -> {
Chip chip = ((Chip) chipGroup.getChildAt(chipGroup.getCheckedChipId()));
if (chip != null) {
for (int i = 0; i < chipGroup.getChildCount(); ++i) {
chipGroup.getChildAt(i).setClickable(true);
}
chip.setClickable(false);
}
});
Brief modification of #adriennoir 's answer (in Kotlin). Thanks for the help!
Note that getChildAt() takes an index.
for (i in 0 until group.childCount) {
val chip = group.getChildAt(i)
chip.isClickable = chip.id != group.checkedChipId
}
Here's my larger `setOnCheckedChangeListener, for context:
intervalChipGroup.setOnCheckedChangeListener { group, checkedId ->
for (i in 0 until group.childCount) {
val chip = group.getChildAt(i)
chip.isClickable = chip.id != group.checkedChipId
}
when (checkedId) {
R.id.intervalWeek -> {
view.findViewById<Chip>(R.id.intervalWeek).chipStrokeWidth = 1F
view.findViewById<Chip>(R.id.intervalMonth).chipStrokeWidth = 0F
view.findViewById<Chip>(R.id.intervalYear).chipStrokeWidth = 0F
currentIntervalSelected = weekInterval
populateGraph(weekInterval)
}
R.id.intervalMonth -> {
view.findViewById<Chip>(R.id.intervalWeek).chipStrokeWidth = 0F
view.findViewById<Chip>(R.id.intervalMonth).chipStrokeWidth = 1F
view.findViewById<Chip>(R.id.intervalYear).chipStrokeWidth = 0F
currentIntervalSelected = monthInterval
populateGraph(monthInterval)
}
R.id.intervalYear -> {
view.findViewById<Chip>(R.id.intervalWeek).chipStrokeWidth = 0F
view.findViewById<Chip>(R.id.intervalMonth).chipStrokeWidth = 0F
view.findViewById<Chip>(R.id.intervalYear).chipStrokeWidth = 1F
currentIntervalSelected = yearInterval
populateGraph(yearInterval)
}
}
}
Most of the answers are great and really helpful for me. Another slight modification to #adriennoir and #Todd DeLand, to prevent unchecking already checked chip in a setSingleSelection(true) ChipGroup, here's my solution:
for (i in 0 until chipGroup.childCount) {
val chip = chipGroup.getChildAt(i) as Chip
chip.isCheckable = chip.id != chipGroup.checkedChipId
chip.isChecked = chip.id == chipGroup.checkedChipId
}
For me, I just need to prevent the same checked Chip to be unchecked without making it non-clickable. This way, the user can still click the checked chip and see the fancy ripple effect and nothing will happen.
If singleSelection doesn't work with added dynamically chips, you must generate id for each chip when create them and then add to ChipGroup.
val chip = inflater.inflate(
R.layout.item_crypto_currency_category_chip,
binding.chipGroupCryptoCurrencyCategory,
false) as Chip
chip.id = ViewCompat.generateViewId()
binding.chipGroupCryptoCurrencyCategory.addView(chip)
//Set default value with index 0 when ChipGroup created.
if (index == 0) binding.chipGroupCryptoCurrencyCategory.check(chip.id)
item_crypto_currency_category_chip.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/chip_smart_contract"
style="#style/Widget.Signal.Chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
item_crypto_currency_tag_category.xml
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_6x"
android:scrollbars="none"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.ChipGroup
android:id="#+id/chip_group_crypto_currency_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleSelection="true"
app:singleLine="true"
/>
</HorizontalScrollView>
Result:
This is how I did it:
var previousSelection: Int = default_selection_id
chipGroup.setOnCheckedChangeListener { chipGroup, id ->
if (id == -1) //nothing is selected.
chipGroup.check(previousSelection)
else
previousSelection = id
This is my working solution
mChipGroup.setOnCheckedChangeListener((group, checkedId) -> {
for (int i = 0; i < mChipGroup.getChildCount(); i++) {
Chip chip = (Chip) mChipGroup.getChildAt(i);
if (chip != null) {
chip.setClickable(!(chip.getId() == mChipGroup.getCheckedChipId()));
}
}
});
I have a quiz app, and every question has 4 answers, 2 of them are the correct ones. I use CheckBox for the answers. What I want is when the user clicks on 2 of the answers, then the remaining 2 to get unchecked. With other words, only 2 checked CheckBox at the time, and if the user has 2 checked and checks third one, then one of the two checked to get unchecked. I write a code that it is "half-working". When I check CheckBox starting from the first to the last is working, but clicking from the last to the first, nothing happens...
public void checkBoxClicked(View view) {
switch (view.getId()) {
case R.id.checkBoxOne:
case R.id.checkBoxTwo:
case R.id.checkBoxThree:
case R.id.checkBoxFour:
if (checkBoxOne.isChecked() && checkBoxTwo.isChecked()) {
checkBoxThree.setEnabled(false);
checkBoxFour.setEnabled(false);
}else {
checkBoxThree.setEnabled(true);
checkBoxFour.setEnabled(true);
}
if (checkBoxOne.isChecked() && checkBoxThree.isChecked()) {
checkBoxTwo.setEnabled(false);
checkBoxFour.setEnabled(false);
}else {
checkBoxTwo.setEnabled(true);
checkBoxFour.setEnabled(true);
}
if (checkBoxOne.isChecked() && checkBoxFour.isChecked()) {
checkBoxTwo.setEnabled(false);
checkBoxThree.setEnabled(false);
}else {
checkBoxTwo.setEnabled(true);
checkBoxThree.setEnabled(true);
}
if (checkBoxTwo.isChecked() && checkBoxThree.isChecked()) {
checkBoxOne.setEnabled(false);
checkBoxFour.setEnabled(false);
}else {
checkBoxOne.setEnabled(true);
checkBoxFour.setEnabled(true);
}
if (checkBoxTwo.isChecked() && checkBoxFour.isChecked()) {
checkBoxOne.setEnabled(false);
checkBoxThree.setEnabled(false);
}else {
checkBoxOne.setEnabled(true);
checkBoxThree.setEnabled(true);
}
if (checkBoxThree.isChecked() && checkBoxFour.isChecked()) {
checkBoxOne.setEnabled(false);
checkBoxTwo.setEnabled(false);
}else {
checkBoxOne.setEnabled(true);
checkBoxTwo.setEnabled(true);
}
break;
I would try tracking the boxes that are checked using an array, (a queue would work perfect for this). When the user clicks on a checkbox, check if your array has two entries. If it has less than 2 entries, add the new checkbox to the list. If it has two entries, remove the first checkbox from the list, and add the new checkbox.
After your tracking code, you can simply uncheck ALL of the check boxes and only check those that you want.
Here I use an ArrayList for simplicity, but even a simple array would work. You could also use the id's instead of the actual views.
***Update Very Simple Working example.
Activity
public class TestActivity extends AppCompatActivity implements View.OnClickListener{
private ArrayList<CheckBox> mChecks;
private ArrayList<CheckBox> mSelectedChecks;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_layout);
mChecks = new ArrayList<CheckBox>();
mSelectedChecks = new ArrayList<CheckBox>();
//Load All checkboxes
CheckBox check1 = (CheckBox)findViewById(R.id.check1);
CheckBox check2 = (CheckBox)findViewById(R.id.check2);
CheckBox check3 = (CheckBox)findViewById(R.id.check3);
CheckBox check4 = (CheckBox)findViewById(R.id.check4);
//Add to tracking list
mChecks.add(check1);
mChecks.add(check2);
mChecks.add(check3);
mChecks.add(check4);
//Add Click listener
for(CheckBox c : mChecks) {
c.setOnClickListener(this);
}
}
#Override
public void onClick(View view) {
CheckBox c = (CheckBox)view;
if(mSelectedChecks.contains(c)) {
mSelectedChecks.remove(c);
} else {
if(mSelectedChecks.size() < 2) {
mSelectedChecks.add(c);
} else {
mSelectedChecks.remove(0);
mSelectedChecks.add(c);
}
}
drawResults();
}
public void drawResults() {
for(CheckBox c : mChecks) {
c.setChecked(mSelectedChecks.contains(c));
}
}
}
Layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:text="Check 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/check1"/>
<CheckBox
android:text="Check 2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/check2"/>
<CheckBox
android:text="Check 3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/check3"/>
<CheckBox
android:text="Check 4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/check4"/>
</LinearLayout>
I want to make a custom list of radio groups, that should has a text view and a radio group in each item and each radio group contains radio buttons, i could do it but there's a problem...., the radio buttons are repeated more than it should be in each item and i can select more than one radio button in a radio group which is wrong,
here's what i've done:
PollsQuestionsAdapter
public class PollsQuestionsAdapter extends ArrayAdapter {
Context context;
List<PollQuestion> pollQuestionList;
public PollsQuestionsAdapter(Context context, List<PollQuestion> pollQuestionList) {
super(context, R.layout.polls_questions_list_item, pollQuestionList);
this.context = context;
this.pollQuestionList = pollQuestionList;
}
#Override
public int getCount() {
return pollQuestionList.size();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.polls_questions_list_item, parent, false);
}
RadioGroup rgAnswer;
TextView tvQuestion;
tvQuestion = (TextView) convertView.findViewById(R.id.polls_questions_list_item_question_name);
rgAnswer = (RadioGroup) convertView.findViewById(R.id.polls_questions_list_item_answer);
String questionName;
List<PollAnswer> answerList;
if (Language.lang.equals("EN") || Language.lang.equals("En") || Language.lang.equals("en"))
questionName = pollQuestionList.get(position).getQuestionTextEN();
else
questionName = pollQuestionList.get(position).getQuestionTextAR();
answerList = pollQuestionList.get(position).getAnswersList();
rgAnswer.setTag(pollQuestionList.get(position).getQuestionId()); // to use it when you get the value of question id
for (int i = 0; i < answerList.size(); i++) {
RadioButton radioButton = new RadioButton(context);
if (Language.lang.equals("EN") || Language.lang.equals("En") || Language.lang.equals("en"))
radioButton.setText(answerList.get(i).getAnswerTextEN());
else
radioButton.setText(answerList.get(i).getAnswerTextAR());
radioButton.setId(answerList.get(position).getAnswerId()); // to use it when you get the value of the answer id
rgAnswer.addView(radioButton);
}
tvQuestion.setText(questionName);
return convertView;
}
}
polls_questions_list_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1E5BAC"
android:orientation="vertical"
android:padding="#dimen/padding_normal">
<TextView
android:id="#+id/polls_questions_list_item_question_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#android:color/white"
android:textSize="#dimen/font_large"
android:textStyle="bold" />
<RadioGroup
android:id="#+id/polls_questions_list_item_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white">
</RadioGroup>
</LinearLayout>
and here's how i called the adapter in my activity:
List<PollQuestion> pollQuestionList = new ArrayList<>();
ArrayList<PollAnswer> pollAnswerList = new ArrayList<>();
pollAnswerList.add(new PollAnswer(1, "Yes", "نعم"));
pollAnswerList.add(new PollAnswer(2, "No", "لا"));
pollQuestionList.add(new PollQuestion("مواعيد المحاضرات بها تعارض", "Schedule has conflict", 1, pollAnswerList));
pollAnswerList = new ArrayList<>();
pollAnswerList.add(new PollAnswer(3, "High", "مرتفعة"));
pollAnswerList.add(new PollAnswer(4, "Medium", "متوسطة"));
pollAnswerList.add(new PollAnswer(5, "Low", "منخفضة"));
pollQuestionList.add(new PollQuestion("مواعيد المحاضرات موزعة بالتساوى خلال الاسبوع", "The lectures schedule is balanced during week",2, pollAnswerList));
PollsQuestionsAdapter adapter = new PollsQuestionsAdapter(PollsQuestionsActivity.this, pollQuestionList);
listView.setAdapter(adapter);
and this is the result :
result1
result2
the first item should contain:
Yes and No only
the second item should contain:
High, Medium and Low only
and the radio buttons in each radio group should should be selected together, only one button is pressed and the others are disabled which doesn't happen in the items here.
so, could any one tell me what did i do wrong ?
Thanks in advance.