2
私は単純なチェックボックスを作ろうとしています。チェックボックスをオンにすると、チェックボックスのテキストでトーストを表示します。チェックボックスのループとAndroidのテキストの取得
これは私が試してみましたが、
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