I have ListAdapter
which fills list with TextView of category and RadioButton
which is to be checked. So, the problem is that I want user to define which category he wants through List and when he clicks on RadioButton
, others should be unchecked and so on. I need to set somehow the ID of this RadioButtons and I'm doing that in getView(...)
method in ListAdapter
but when it calls for second time that method, he doesn't find that RadioButton
and I get error while trying to set ID of this RadioButton view. I was debugging it, and first time it finds the view through method findViewById
, but second time it doesn't.
I think I might know the problem for it -> when second time it goes to find the view by ID, it can't find it since I've put already other Identifier on the first call, but how can I set unique identifiers for my RadioButtons in the list then?
Here is my code: getView:
public View getView(int index, View view, ViewGroup parent) {
if (view == null){
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.category_item, parent, false);
}
ListCategoryItem category = categories.get(index); // categories is list
TextView title = (TextView) view.findViewById(R.id.categoryTitle);
naziv.setText(kategorija.getNazivKategorije());
RadioButton radioBtn = (RadioButton) view.findViewById(R.id.categoryRadioButton);
radioBtn.setId(category.getIdCategory());
return view;
}
and here is my layout for category_item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/categoryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:paddingTop="5dp"
/>
<RadioButton
android:id="@+id/categoryRadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textSize="15sp"
android:onClick="onRadioButtonClick"/>
So, how to set unique identifier to my RadioButtons in view properly or can I make somehow group of RadioButtons which will care for itself that when other one is checked, others to be unchecked - something how in HTML is solved up.