我是android的新手..
我在Nextbutton
面临问题,同时显示问题的下四个选项答案......
在我第一次设置文本时,我得到了正确的问题并匹配了四个选项答案。我需要的是......
我有一个nextbutton
用于显示下一个问题和答案。点击下一个按钮我可以得到下一个问题..
同样我需要从arraylist获得下面的四个选项.... 如何实现这个?任何帮助将不胜感激...非常感谢提前..
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事件中实现radiobutton文本?
答案 0 :(得分:0)
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));
}
});
答案 1 :(得分:0)
您可以使用两个ArrayLists,第一个用于所有问题,第二个用于每个问题的四个选项,类似这样..
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);
以这种方式提出所有答案
然后在OnClick of nextButton上做
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());