2
간단한 체크 박스를 만들려고하는데, 체크 박스가 선택되면 체크 박스 텍스트로 토스트를 표시하고 싶습니다. 체크 박스를 반복하면서 안드로이드에서 텍스트 받기
이
내 내가 시도 코드 만이 내 레이아웃입니다nextscreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout layout = (RelativeLayout)findViewById(R.id.DSP);
for (int i = 0; i < layout.getChildCount(); i++) {
v = layout.getChildAt(i);
if (v instanceof CheckBox) {
if (((CheckBox) v).isChecked()){
String text = String.valueOf(((CheckBox) v).getText());
Log.d("@@@@@@@@@" , "somethinng" +text);
}
}
}
}
});
을 작동하지 않습니다.
<RelativeLayout
android:layout_below="@+id/customer_email_addnew_edittext"
android:layout_width="match_parent"
android:id="@+id/DSP"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/toi"
android:layout_width="match_parent"
android:layout_margin="5dp"
android:layout_height="wrap_content"
android:text="Times of India"
android:background="@drawable/customborder"/>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/danikjagran"
android:layout_width="match_parent"
android:layout_below="@+id/toi"
android:layout_margin="5dp"
android:layout_height="wrap_content"
android:text="Times of India"
android:background="@drawable/customborder"/>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/htimes"
android:layout_width="match_parent"
android:layout_below="@+id/danikjagran"
android:layout_margin="5dp"
android:layout_height="wrap_content"
android:text="Times of India"
android:background="@drawable/customborder"/>
<Button
android:id="@+id/conntinue"
android:text="continue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
모든 확인란을 반복하여 텍스트를 가져올 수있는 방법이 있습니까?
감사합니다,하지만 당신은 다른이 할 동일한 비트를보다 효율적으로 수행하는 논리. – Firdoesh
@Firdoesh가 예제를 추가했습니다. – nandsito