0

次の質問を表示しているときに、[次へ]ボタンで問題が発生しています。

初めてテキストを設定すると、正しい質問が表示され、4つのオプションの回答が一致しました。必要なのはです。

次の質問と回答を表示するための[次へ]ボタンがあります。次のボタンをクリックすると、次の質問の次の4つのオプションが表示されます。しかし、4回クリックすると次の質問が表示されますが、答えは正しいです。

私が間違っているのは何ですか?私が欠けているものは何ですか?

どんな助けでもいただければ幸いです。

    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));
  }
});
  }
4

1 に答える 1

2

で質問とそのオプションを管理しようとしていると思いますnext/previous buttons click

私はあなたが望むのと同じアプリの1つで達成しました:

Step1@int count=0グローバルに1つの定義を取ります。

Step2 @アクティビティが最初に呼び出されると、最初の質問がオプションとともに表示されます。

setValues(count);//ここでは、メソッドという名前のsetValues内のtextviewに質問とオプションを設定しています。

Step3 @onClick of NextButton以下のような状態を確認してください:

if (count == question.size() - 1) {
    finish();
    break;
} 

else {
count++;
setValues(count);
   }

Step4 @onClick of PreviousButton以下のような状態を確認してください:

if (count <= 0) {
Toast.makeText(OnPurposeUPSQuesAcitivty.this, "First Record",Toast.LENGTH_SHORT).show();
break;
} else {
count--;
setValues(count);
}

あなたの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);
}

..........。

Last Point @コードを確認した後、オプションに値を設定する方法に気づきませんでした。

これ

btn_practice1.setText(answ1.get((k * 4)+0));

上記のコード行について説明してください。私の答えを更新します。それ以外の場合は、上記の手順で説明したように、私のソリューションを使用できます。

于 2013-02-01T07:19:21.230 に答える