我正在製作測驗應用程序。如果用戶輸入了正確答案,他們的得分就會達到+1。 但是,我想這樣做,如果一個提示按鈕被點擊,然後他們沒有得到他們的分數更新。如果按鈕已被點擊,Android不會更新分數
我的代碼現在
public class FragmentTwo extends Fragment {
private EditText userAnswer;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_fragment_two, null);
userAnswer = (EditText)v.findViewById(R.id.editText);
final TextView tv = (TextView)v.findViewById(R.id.showCorrect);
final TextView hintv = (TextView)v.findViewById(R.id.textHint);
//final int a;
final Button submit = (Button)v.findViewById(R.id.submitBtn1);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String theAnswer = (userAnswer.getText().toString());
if (theAnswer.equalsIgnoreCase("Greece")) {
if (hintv.isEnabled()) { //Doesn't work
((Play) getActivity()).updateScore(1);
}
tv.setText("Correct!");
} else {
tv.setText("Wrong");
}
submit.setEnabled(false);
}
});
final Button skip = (Button)v.findViewById(R.id.skipBtn);
skip.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
submit.setEnabled(false);
}
});
final Button hint = (Button)v.findViewById(R.id.hintBtn);
hint.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
hintv.setText("The capital is Athens \n The country is in Europe \n It starts with G... ");
hint.setEnabled(false);
}
});
if語句我應該寫什麼,而不是看爲以下?
謝謝你的幫助! –