How to do the next button action?(如何进行下一步按钮操作?)
问题描述
在显示下一个问题时,我在下一个"按钮中遇到问题.
在我第一次设置文本时,我得到了正确的问题并匹配了四个选项答案.我需要的是.
我有一个下一步"按钮,用于显示下一个问题和答案.当我单击下一个按钮时,我可以获得下一个问题的下四个选项.但是我点击next四次后无法得到下一个问题,它显示下一个问题,但答案是正确的.
我做错了什么?我错过了什么?
任何帮助将不胜感激.
<块引用> protected String doInBackground(String... Args) {列出<NameValuePair>params = new ArrayList<NameValuePair>();System.out.println("酷");params.add(new BasicNameValuePair("tid", tid));json = jsonParser.makeHttpRequest(url_get_quesurl, "GET", 参数);System.out.println("得到的问题值");Log.d("所有组:", json.toString());System.out.println("问题");尝试 {int 成功 = json.getInt(TAG_SUCCESS);System.out.println("成功");如果(成功 == 1){System.out.println("成功");组 = json.getJSONArray(TAG_GROUP);System.out.println("结果成功++"+groups);for (int i = 0; i < groups.length();i++) {JSONObject c = groups.getJSONObject(i);字符串问题 = c.getString(TAG_QUES);System.out.println("正在检查::"+问题);ques1.add(问题);字符串答案 = c.getString(TAG_ANSW);System.out.println("正在检查::"+answer);answ1.add(答案);}} 别的 {显示警报();}} 捕捉(JSONException e){System.out.println("错误"+e.toString());}返回空值;}受保护的无效 onPostExecute(字符串 file_url){pDialog.dismiss();ques1=new ArrayList(new ArrayList(ques1));//j=0;TextView txtque = (TextView) findViewById(R.id.que_txt);txtque.setText(ques1.get(j));//这里我得到了问题//和单选按钮文本中的答案answ1=new ArrayList(new ArrayList(answ1));btn_practice1.setText(answ1.get(0));btn_practice2.setText(answ1.get(1));btn_practice3.setText(answ1.get(2));btn_practice4.setText(answ1.get(3));btn_practicerg.setOnCheckedChangeListener(new OnCheckedChangeListener() {@覆盖公共无效 onCheckedChanged(无线电组组,int checkId){RadioButton radioButton = (RadioButton) findViewById(checkedId);//Toast.makeText(Question.this, "" + radioButton.getText(), 2000).show();TextView txtRadio = (TextView) findViewById(R.id.rdtxt);txtRadio.setText("" + radioButton.getText());}});按钮 nextBtn = (Button) findViewById(R.id.nxt_btn);nextBtn.setOnClickListener(new Button.OnClickListener(){公共无效 onClick(查看 v){j++;TextView txtque = (TextView) findViewById(R.id.que_txt);txtque.setText(ques1.get(j));//这里我没有得到下一个问题//但我可以得到接下来的四个选项//单选按钮文本k++;btn_practice1.setText(answ1.get((k*4)+0));btn_practice2.setText(answ1.get((k*4)+1));btn_practice3.setText(answ1.get((k*4)+2));btn_practice4.setText(answ1.get((k*4)+3));}});Button previousbtn = (Button) findViewById(R.id.prv_btn);previousbtn.setOnClickListener(new Button.OnClickListener(){公共无效 onClick(查看 v){j——;TextView txtque = (TextView) findViewById(R.id.que_txt);txtque.setText(ques1.get(j));//这里我也没有得到敏感的问题//但我无法在其中获得四个选项//单选按钮文本k——;btn_practice1.setText(answ1.get((k*4)+0));btn_practice2.setText(answ1.get((k*4)+1));btn_practice3.setText(answ1.get((k*4)+2));btn_practice4.setText(answ1.get((k*4)+3));}});}
我假设,您正在尝试在 next/previous 按钮单击
上管理问题及其选项.
我在我的一个应用中实现了你想要的:
Step1@ 取一个 int count=0
全局定义.
Step2@ 最初调用活动时,第一个问题将与选项一起显示.
setValues(count);
//这里我在 setValues 命名方法中为 textview 设置问题和选项.
Step3@ onClick of NextButton
检查条件如下:
if (count == question.size() - 1) {结束();休息;}别的 {计数++;设置值(计数);}
Step4@ onClick of PreviousButton
检查条件如下:
if (count <= 0) {Toast.makeText(OnPurposeUPSQuesAcitivty.this, "第一条记录",Toast.LENGTH_SHORT).show();休息;} 别的 {数数 - ;设置值(计数);}
您的 setValue
方法如下所示:
public void setValues(int j) {txtque.setText(ques1.get(j));btn_practice1.setText(answ1.get(j);btn_practice2.setText(answ1.get(j);btn_practice3.setText(answ1.get(j);btn_practice4.setText(answ1.get(j);}
...........
最后一点@ 在查看您的代码后,我没有发现您如何为选项设置值.
这个
<块引用>btn_practice1.setText(answ1.get((k*4)+0));
你会解释上面的代码行吗,会更新我的答案,否则你可以按照我上面提到的步骤明智地使用我的解决方案.
I'm facing a problem in Next button while displaying the next question.
In my first time set text I'm getting the correct question and matched four option answers. What I needed is.
I have a Next button for displaying the next question and answers. When I click on next button I can get the next four options for next question. But I can't get next question after four times I click on next it shows next question, but answers are correct.
What I'm doing wrong? what I'm missing?
Any help would be appreciated.
protected String doInBackground(String... Args) { List<NameValuePair> params = new ArrayList<NameValuePair>(); System.out.println("cool"); params.add(new BasicNameValuePair("tid", tid)); json = jsonParser.makeHttpRequest(url_get_quesurl, "GET", params); System.out.println("ques value got"); Log.d("All Groups: ", json.toString()); System.out.println("question"); try { int success = json.getInt(TAG_SUCCESS); System.out.println("Success"); if (success == 1) { System.out.println("Success"); groups = json.getJSONArray(TAG_GROUP); System.out.println("Result Success+++"+groups); for (int i = 0; i < groups.length();i++) { JSONObject c = groups.getJSONObject(i); String question = c.getString(TAG_QUES); System.out.println("Checking ::"+question); ques1.add(question); String answer = c.getString(TAG_ANSW); System.out.println("Checking ::"+answer); answ1.add(answer); } } else { showAlert(); } } catch (JSONException e) { System.out.println("Error "+e.toString()); } return null; } protected void onPostExecute(String file_url) { pDialog.dismiss(); ques1=new ArrayList<String>(new ArrayList<String>(ques1)); // j=0; TextView txtque = (TextView) findViewById(R.id.que_txt); txtque.setText(ques1.get(j)); // here im getting the question // and answers in radiobutton text answ1=new ArrayList<String>(new ArrayList<String>(answ1)); btn_practice1.setText(answ1.get(0)); btn_practice2.setText(answ1.get(1)); btn_practice3.setText(answ1.get(2)); btn_practice4.setText(answ1.get(3)); btn_practicerg.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { RadioButton radioButton = (RadioButton) findViewById(checkedId); // Toast.makeText(Question.this, "" + radioButton.getText(), 2000).show(); TextView txtRadio = (TextView) findViewById(R.id.rdtxt); txtRadio.setText("" + radioButton.getText()); } }); Button nextBtn = (Button) findViewById(R.id.nxt_btn); nextBtn.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ j++; TextView txtque = (TextView) findViewById(R.id.que_txt); txtque.setText(ques1.get(j)); // here im not getting the next question // but i can get the next four options in // radiobutton text k++; btn_practice1.setText(answ1.get((k*4)+0)); btn_practice2.setText(answ1.get((k*4)+1)); btn_practice3.setText(answ1.get((k*4)+2)); btn_practice4.setText(answ1.get((k*4)+3)); } }); Button previousbtn = (Button) findViewById(R.id.prv_btn); previousbtn.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ j--; TextView txtque = (TextView) findViewById(R.id.que_txt); txtque.setText(ques1.get(j)); // here also im not getting the perivous question // but i cant get perivous four options in // radiobutton text k--; btn_practice1.setText(answ1.get((k*4)+0)); btn_practice2.setText(answ1.get((k*4)+1)); btn_practice3.setText(answ1.get((k*4)+2)); btn_practice4.setText(answ1.get((k*4)+3)); } }); }
I assume, you are trying to manage question and its options on next/previous buttons click
.
I achieved in my one of app same as you want:
Step1@ take one int count=0
define globally.
Step2@ when activity is called initially first question will be display with options.
setValues(count);
// here I am setting question and options to textview inside setValues named method.
Step3@ onClick of NextButton
check condition something like below:
if (count == question.size() - 1) {
finish();
break;
}
else {
count++;
setValues(count);
}
Step4@ onClick of PreviousButton
check condition something like below:
if (count <= 0) {
Toast.makeText(OnPurposeUPSQuesAcitivty.this, "First Record",Toast.LENGTH_SHORT).show();
break;
} else {
count--;
setValues(count);
}
Your setValue
method something look like below:
public void setValues( int j) {
txtque.setText(ques1.get(j));
btn_practice1.setText(answ1.get(j);
btn_practice2.setText(answ1.get(j);
btn_practice3.setText(answ1.get(j);
btn_practice4.setText(answ1.get(j);
}
...........
Last Point@ After review your code, I don't came across that how you are setting values to options.
this
btn_practice1.setText(answ1.get((k*4)+0));
Will you explain above line of code, will update my answer, else you can use my solution as I mention above steps wise.
这篇关于如何进行下一步按钮操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何进行下一步按钮操作?


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01