【问题标题】:how to implement the radiobuttons text for multiple answers?如何实现多个答案的单选按钮文本?
【发布时间】:2013-01-15 06:38:46
【问题描述】:

我是安卓新手..

我在 Nextbutton 中遇到问题,同时显示问题的下四个选项答案...

在我第一次设置文本时,我得到了正确的问题并匹配了四个选项答案。我需要的是..

我有一个nextbutton 用于显示下一个问题和答案。当单击下一个按钮时,我可以得到下一个问题..

同时我需要从数组列表中获取接下来的四个选项.... 如何实现这一点?任何帮助将不胜感激......非常感谢提前......

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));
            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));
        Button nextBtn = (Button) findViewById(R.id.nxt_btn);

        nextBtn.setOnClickListener(new Button.OnClickListener(){
        @Override
        public void onClick(View v){  

          j++;
          TextView txtque = (TextView) findViewById(R.id.que_txt); 
          txtque.setText(ques1.get(j));         
         }
       });
}

如何在 Nextbutton 的 onClick 事件中实现单选按钮文本?

【问题讨论】:

  • @vikalp patel 如何实现这个?任何帮助
  • @ram kiran 如何实现这对我有帮助..

标签: android textview radio-button


【解决方案1】:
    nextbtn.setOnClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {

            j++;// j is your ques1 Array index number
            txtque.setText(ques1.get(j));
                            k++;  // k is your answ1 Array index number
            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”是我的 ques1 arrayList 的索引号
  • 我有两个数组,一个用于问题,另一个用于答案。所以问题数组索引是“i”,答案数组索引是“k”..但是第一个问题和前四个选项我得到了正确的。当我单击下一个时,我在单选按钮中遇到问题...我没有得到接下来的四个选项...如何实现这个...
【解决方案2】:

您可以使用两个 ArrayList,第一个用于所有问题,第二个用于每个问题的四个选项,类似这样..

ArrayList<String> allQue = new ArrayList<String>();

ArrayList<HashMap<String, String>> options = new ArrayList<HashMap<String, String>>();

HashMap<String, String> map = new HashMap<String, String>();

map.put("optionFirst","your option");
map.put("optionSecond","your option");
map.put("optionThird","your option");
map.put("optionFourth","your option");

options.add(map);

这样把你所有的答案都写出来

然后在nextButton的OnClick上做

txtque.setText(allQur.get(j).toString());

对于选项...

 btn_practice1.setText(options.get(j).get("optionFirst").toString());
 btn_practice2.setText(options.get(j).get("optionSecond").toString());
 btn_practice3.setText(options.get(j).get("optionThird").toString());
 btn_practice4.setText(options.get(j).get("optionFour").toString());

【讨论】:

  • 我在 ques1 中为所有问题(4 个问题)提供了单独的数组,在 answ1 中为所有答案(每个问题 16 个选项 4 个选项)提供了单独的数组..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-10-19
  • 2016-04-02
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-19
相关资源
最近更新 更多