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 book O pencil Total is : 。. .
我想对选定的复选框求和。如果书=10,铅笔=5。如何?
android:id="@+id/book"在您的 xml ( , ) 中为每个复选框提供一个唯一 ID ,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;