@Override public void onFocusChange(View v, boolean hasFocus) { switch (v.getId()) { case R.id.edt_topic: if (hasFocus) { topic.setErrorEnabled(true); topic.setError(getString(R.string.worldslimit, TOPIC_LENGTH_MIN, TOPIC_LENGTH_MAX)); } else { topic.setErrorEnabled(false); } break; case R.id.edt_option_a: if (hasFocus) { option_a.setErrorEnabled(true); if (mQuestion.getQuestionType().equals("judge")) { option_a.setError(getString(R.string.correct_or_wrong)); } else { option_a.setError( getString(R.string.worldslimit, OPTION_LENGTH_MIN, OPTION_LENGTH_MAX)); } } else { option_a.setErrorEnabled(false); } break; case R.id.edt_option_b: if (hasFocus) { option_b.setErrorEnabled(true); if (mQuestion.getQuestionType().equals("judge")) { option_b.setError(getString(R.string.correct_or_wrong)); } else { option_b.setError( getString(R.string.worldslimit, OPTION_LENGTH_MIN, OPTION_LENGTH_MAX)); } } else { option_b.setErrorEnabled(false); } break; case R.id.edt_option_c: if (hasFocus) { option_c.setErrorEnabled(true); option_c.setError(getString(R.string.worldslimit, OPTION_LENGTH_MIN, OPTION_LENGTH_MAX)); } else { option_c.setErrorEnabled(false); } break; case R.id.edt_option_d: if (hasFocus) { option_d.setErrorEnabled(true); option_d.setError(getString(R.string.worldslimit, OPTION_LENGTH_MIN, OPTION_LENGTH_MAX)); } else { option_d.setErrorEnabled(false); } break; } }
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)); } }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.type_choice: option_b.setVisibility(View.VISIBLE); option_c.setVisibility(View.VISIBLE); option_d.setVisibility(View.VISIBLE); mQuestion.setQuestionType("choice"); break; case R.id.type_judgment: option_b.setVisibility(View.GONE); option_c.setVisibility(View.GONE); option_d.setVisibility(View.GONE); option_b.getEditText().setText(""); option_c.getEditText().setText(""); option_d.getEditText().setText(""); mQuestion.setQuestionType("judge"); break; } topic.getEditText().requestFocus(); }
private void uploadQuestion() { if (mApplication.isLogin()) { showProgress(); isUpload = true; if (null != bitmap && null == pic) { MobclickAgent.onEvent(this, "uploadQP"); NetInterface.uploadPic(this, mApplication.user, bitmap, this); return; // 有图片但未上传图片 } if (mQuestion.getQuestionType().equals("choice")) { MobclickAgent.onEvent(this, "uploadChoice"); } else { MobclickAgent.onEvent(this, "uploadJudge"); } NetInterface.uploadQuestion(this, mApplication.user, mQuestion, pic, this); } else { callLogin(REQUEST_LOGIN); } }
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; }