Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私の方が新しいです。Java で問題が発生します。
XML では、チェックボックスが 2 つある場合、O 本 O 鉛筆 合計は : です。. .
選択したチェックボックスを合計したい。本=10、鉛筆=5の場合。どのように?
チェックボックスのそれぞれに一意の ID を xml ( android:id="@+id/book"、android:id="@+id/pencil") に与え、コード チェックで次のようにチェックされているかどうかを確認します。
android:id="@+id/book"
android:id="@+id/pencil"
int sum = 0; if (((CheckBox)findViewById(R.id.book)).isChecked()) sum += 10; if (((CheckBox)findViewById(R.id.pencil)).isChecked()) sum += 5;