나는 라디오 버튼에 대한 사용자 정의보기를 만들었습니다. 어떻게 사용자 정의보기에서 RadioButton의 값을 가져올 수 있으며 한 번에 하나의 라디오 버튼을 선택하고 싶습니다.Android : 사용자 정의보기에서 RadioButton의 값 받기
public void getData(){
cappingLayout.removeAllViews();
for (Capping capping: productList.getCappingList()){
if (getActivity()!=null) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.product_capping, cappingLayout, false);
cappingRadio = (RadioButton) view.findViewById(R.id.fragment_product_detail_capping);
cappingRadio.setText(capping.getCapping_type());
cappingLayout.addView(view);
}
}
}
Product_capping.xml
<RadioButton
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_product_detail_capping"
style="@style/Widget.AppCompat.CompoundButton.CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
tools:text="Normal"/>
나는 버튼을 클릭 한 후 라디오 버튼의 값을 얻을합니다.
으로 Value, 라디오 버튼과 관련된 텍스트를 의미합니까? –
예. 서버에서 데이터를 검색했지만 버튼 클릭 이벤트 –
에서 checked radioButton의 값을 가져올 수없는 경우'radioButton.isChecked'를 사용하여 선택 여부를 확인하거나 'radioButton.getText'를 사용하여 내용을 가져올 수 있습니다. 라디오 버튼 –