我现在面临的下一步按钮的一个问题,同时显示了下一个问题。
在我第一次组文本我得到了正确的问题和匹配四个选购答案。我需要的是。
我有一个Next按钮,显示下一个问题和答案。当我点击下一步按钮,我可以在接下来的四个选项下一个问题。但我不能经过四次我点击下一步就说明一个问题,但答案是正确的。让下一个问题
我在做什么错了?我缺少的是什么?
任何帮助将是AP preciated。
保护字符串doInBackground(字符串参数... args){
名单<的NameValuePair> PARAMS =新的ArrayList<的NameValuePair>();
的System.out.println(酷);
params.add(新BasicNameValuePair(TID,TID));
JSON = jsonParser.makeHtt prequest(url_get_quesurl,GET,则params);
的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(结果成功++++组);
的for(int i = 0; I< groups.length();我++){
JSONObject的C = groups.getJSONObject(我);
字符串的问题= c.getString(TAG_QUES);
的System.out.println(检查::+问题);
ques1.add(问题);
字符串的答案= c.getString(TAG_ANSW);
的System.out.println(检查::+答案);
answ1.add(答案);
}
} 其他 {
showAlert();
}
}赶上(JSONException E){
的System.out.println(错误+ e.toString());
}
返回null;
}
保护无效onPostExecute(字符串file_url){
pDialog.dismiss();
ques1 =新的ArrayList<字符串>(新的ArrayList<字符串>(ques1));
// J = 0;
TextView的txtque =(TextView中)findViewById(R.id.que_txt);
txtque.setText(ques1.get(J)); //这里即时得到的问题
//并在单选按钮的文字答案
answ1 =新的ArrayList<字符串>(新的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(新OnCheckedChangeListener(){
@覆盖
公共无效onCheckedChanged(RadioGroup中组,诠释checkedId){
单选按钮单选按钮=(单选)findViewById(checkedId);
// Toast.makeText(Question.this,+ radioButton.getText(),2000).show();
TextView的txtRadio =(TextView中)findViewById(R.id.rdtxt);
txtRadio.setText(+ radioButton.getText());
}
});
按钮nextBtn =(按钮)findViewById(R.id.nxt_btn);
nextBtn.setOnClickListener(新Button.OnClickListener(){
公共无效的onClick(视图v){
J ++;
TextView的txtque =(TextView中)findViewById(R.id.que_txt);
txtque.setText(ques1.get(J)); //这里我不是让下一个问题
//但是我可以在未来四年选项
//单选按钮文本
ķ++;
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));
}
});
按钮previousbtn =(按钮)findViewById(R.id.prv_btn);
previousbtn.setOnClickListener(新Button.OnClickListener(){
公共无效的onClick(视图v){
j--;
TextView的txtque =(TextView中)findViewById(R.id.que_txt);
txtque.setText(ques1.get(J)); //这里也即时通讯没有得到perivous问题
//但我不能让perivous四个选项中
//单选按钮文本
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));
}
});
}
解决方案
我认为,你试图管理问题及其对下一首/ previous按钮选项点击
。
我在我的应用程序之一,同样达到你想要的:
第一步@需要一个诠释计数= 0
全局定义。
第二步:@当活动被称为最初的第一个问题将是显示器的选择。
setValues方法(计数);
//这里我设置的问题和选项TextView的命名方法setValues方法里面
第三步:@ Next按钮的的onClick
检查条件应该如下:
如果(计数== question.size() - 1){
完();
打破;
}
其他 {
算上++;
setValues方法(计数);
}
第四步:@ previousButton中的onClick
查询条件应该如下:
如果(计数< = 0){
Toast.makeText(OnPurposeUPSQuesAcitivty.this,第一条,Toast.LENGTH_SHORT).show();
打破;
} 其他 {
计数 - ;
setValues方法(计数);
}
您的setValue
法的东西看起来像如下:
公共无效setValues方法(诠释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);
}
...........
最后一点@回顾您的code后,我不碰到那你是如何设置值的选项。
这
btn_practice1.setText(answ1.get((K * 4)+0));
您上面的code线解释,将更新我的答案,否则你可以用我的解决方案,因为我上面提到的步骤明智的。
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.