点击下一步按钮时如何从数组中获取下一个问题..

时间:2013-01-30 08:43:05

标签: android button textview

我是android的新手..

我面临下一个按钮的问题..

我可以在textview中显示第一个问题,当我点击下一个按钮时,我无法在文本视图中看到下一个问题......

我做错了什么,我失踪了什么?

        protected void onPostExecute(String args) {
        pDialog.dismiss();  
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("tid", tid));
        JSONObject json = jsonParser.makeHttpRequest(url_get_quesid, "GET", params);
        json = jsonParser.makeHttpRequest(url_get_quesurl, "GET", params);
         try {
        int success = json.getInt(TAG_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 questionid = c.getString(TAG_QUESID);
        String question = c.getString(TAG_QUES);
        String answer = c.getString(TAG_ANSW);
        System.out.println("Checking ::"+questionid);
        id=questionid;         
        quesid.add(questionid);
                class QuestionData {
        private String questionid;
        private String question;
        private String answer;
        public String getQuestionid() {
        return questionid;
        }
        public void setQuestionid(String questionid) {
              this.questionid = questionid;
        }
        public String getQuestion() {
              return question;
        }
        public void setQuestion(String question) {
              this.question = question;
        }
        public String getAnswer() {
              return answer;
           }
        public void setAnswer(String answer) {
              this.answer = answer;
         }
            }
    final ArrayList < QuestionData > questionDatas = new ArrayList < QuestionData > ();
    //questionDatas.add(questionData);      
    if (firstQuestionParsed) {
        TextView txtque = (TextView) findViewById(R.id.que_txt);
            txtque.setText(question);   *// here im getting last question in the    
                                           //textview im not gettin the first question..                         
    }
     QuestionData questionData = new QuestionData();
     questionData.setQuestionid(questionid);
     questionData.setQuestion(question);
     questionData.setAnswer(answer);
     questionDatas.add(questionData);
         Button nextQuestion = (Button) findViewById(R.id.nxt_btn);
         nextQuestion.setOnClickListener(new OnClickListener() {
          public void onClick(View v) {
         int counter=0;
         if (counter < questionDatas.size()) {
         QuestionData question = questionDatas.get(counter);
         showNextQuestion(question);
         TextView txtque = (TextView) findViewById(R.id.que_txt);
         txtque.setText((CharSequence) question);  *// here i didnt get any question...
         counter++;
       }
    }
    private void showNextQuestion(
    QuestionData question) {
    // TODO Auto-generated method stub
    }
     });
      }
    } else {
      showAlert();
    }
    } catch (JSONException e) {
    System.out.println("Error "+e.toString());
    }    

同时我想在单选按钮中显示多个答案选项..如何设置radiobuttons和radiobutton文本..

提前致谢..

1 个答案:

答案 0 :(得分:1)

你没有在公共空白中写任何代码onClick(View v){} 对于OnClickListener(),您应该在onClick()

中应用值