카테고리의 TextView와 체크리스트에 RadioButton
으로 채우는 ListAdapter
이 있습니다. 그래서 문제는 사용자가 목록을 통해 원하는 범주를 정의하고 그가 RadioButton
을 클릭하면 다른 항목을 선택하지 말아야한다는 것입니다. 어떻게 든이 RadioButtons의 ID를 설정해야하고 메서드에서 ListAdapter
을 호출하지만 두 번째로 메서드를 호출하면 그는 RadioButton
을 찾지 못하고 ID를 설정하는 동안 오류가 발생합니다. 이 RadioButton 뷰. 디버깅 중이었고 처음으로 메소드 findViewById
을 통해 뷰를 찾았지만 두 번째로는 그렇지 않습니다.리스트 어댑터가 보이지 않음
내가 처음으로 다른 식별자를 넣었으므로 두 번째로 ID로보기를 찾으면 찾지 못할 수도 있지만 어떻게해야합니까? 내 RadioButton에 대한 고유 식별자를 목록에 설정합니까? 의 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;
}
여기 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"/>
그럼, 어떻게 내 RadioButtons를 고유 식별자를 설정하는 보기에 적절하게 또는 어떻게 든 다른 그룹이있을 때 스스로를 돌볼 RadioButton 그룹을 만들 수 있습니까? 체크 된 것들, 체크되지 않은 것들 - HTML에서의 해결 방법.
http://stackoverflow.com/questions/7329856/how-to-use-radiogroup-in-listview-custom-adapter보기 – trebron
고마워요,이 게시물도 도움이되었습니다 : http : //developmentality.wordpress .com/2010/11/05/of-rubber-stamps-and-checkboxes-why-your-listview-is broken / – Tommz