private boolean checkParams() { boolean result = false; if (null != mQuestion.getTitle() && TOPIC_LENGTH_MIN <= mQuestion.getTitle().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getTitle().trim().length()) { if (null != mQuestion.getAnswerOne() && OPTION_LENGTH_MIN <= mQuestion.getAnswerOne().trim().length() && OPTION_LENGTH_MAX >= mQuestion.getAnswerOne().trim().length()) { if (mQuestion.getQuestionType().equals("judge")) { if (mQuestion.getAnswerOne().equals(getString(R.string.wrong)) || mQuestion.getAnswerOne().equals(getString(R.string.correct))) { return true; } else { option_a.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_a); return false; } } else { if (null != mQuestion.getAnswerTwo() && OPTION_LENGTH_MIN <= mQuestion.getAnswerTwo().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getAnswerTwo().trim().length()) { if (null != mQuestion.getAnswerThree() && OPTION_LENGTH_MIN <= mQuestion.getAnswerThree().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getAnswerThree().trim().length()) { if (null != mQuestion.getAnswerFour() && OPTION_LENGTH_MIN <= mQuestion.getAnswerFour().trim().length() && TOPIC_LENGTH_MAX >= mQuestion.getAnswerFour().trim().length()) { result = true; } else { // D option_d.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_d); } } else { // C option_c.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_c); } } else { // B option_b.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_b); } } } else { // 答案A长度不正确 option_a.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(option_a); } } else { // 标题长度不正确 topic.getEditText().requestFocus(); YoYo.with(Techniques.Shake).playOn(topic); } return result; }
private void getQuestion() { mQuestion.setTitle(topic.getEditText().getText().toString()); mQuestion.setAnswerOne(option_a.getEditText().getText().toString()); if (mQuestion.getQuestionType().equals("choice")) { mQuestion.setAnswerTwo(option_b.getEditText().getText().toString()); mQuestion.setAnswerThree(option_c.getEditText().getText().toString()); mQuestion.setAnswerFour(option_d.getEditText().getText().toString()); } else if (mQuestion.getAnswerOne().equals(getString(R.string.correct))) { mQuestion.setAnswerTwo(getString(R.string.wrong)); } else if (mQuestion.getAnswerOne().equals(getString(R.string.wrong))) { mQuestion.setAnswerTwo(getString(R.string.correct)); } }