@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_general_test, container, false);
handInBtn=(Button) rootView.findViewById(R.id.handInBtn);
handInBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
Toast toast = Toast.makeText(getActivity(), scores+"", Toast.LENGTH_LONG);
toast.show();
}});
return rootView;
}
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.Radio1a:
if (checked)
scores++;
case R.id.Radio2a:
if (checked)
scores++;
}
}
答案 0 :(得分:0)
在android中你可以创建一个无线电组,并且有一个redio组监听器,这样你就可以获得选择的单选按钮并获得该按钮的值,如果正确则比较正确的答案,然后增加其他离开。
for Example.
RadioGroup
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.d("chk", "id" + checkedId);
if (checkedId.gettext() == "Correct answer") {
//some code
correct++
} else {
//some code
}
}
});