ListAdapter
カテゴリの TextView でリストを埋めるものRadioButton
と、チェックするものがあります。したがって、問題は、ユーザーがリストを通じて必要なカテゴリを定義し、クリックしたときにRadioButton
他のカテゴリのチェックを外す必要があることです。このRadioButtonsのIDをどうにかして設定する必要があり、getView(...)
メソッドinでそれを行っていますが、そのメソッドを2回目ListAdapter
に呼び出すと、彼はそれを見つけられず、このRadioButtonビューのIDを設定しようとするとエラーが発生します。私はそれをデバッグしていましたが、最初は method を介してビューを見つけましたが、2回目はそうではありません。RadioButton
findViewById
私はそれの問題を知っているかもしれないと思います-> 2回目にIDでビューを見つけようとすると、最初の呼び出しですでに他の識別子を設定しているため、それを見つけることができませんが、一意の識別子を設定するにはどうすればよいですか?リスト内の私のRadioButtons?
これが私のコードです: 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"/>
したがって、ビュー内のRadioButtonに一意の識別子を適切に設定する方法、または他のRadioButtonがチェックされているときに他のものがチェックされていないことを気にするRadioButtonのグループを何らかの方法で作成できますか-HTMLでどのように解決されるか。