我是安卓新手。我正在做一个测验应用程序的项目。我在显示问题和答案时遇到问题。
我的问题是我已将问题和答案存储在数组中。问题和答案正在显示,但未按顺序显示。
我从数据库中得到了问题和答案。它们按顺序排列,但在我的数组列表中它不按顺序排列。问题和答案不匹配。
如何通过匹配正确的顺序以正确的顺序显示问题。
请帮助我,并提前非常感谢。
code
protected void onPostExecute(String file_url) {
pDialog.dismiss();
ques1=new ArrayList<String>(new HashSet<String>(ques1));
System.out.println(" Question array:"+ques1);
String[] quesArr = new String [ques1.size()];
quesArr = ques1.toArray(quesArr);
for(String s: quesArr){
Collections.sort(ques1, new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
// TODO Auto-generated method stub
return 0;
}
});
System.out.println("All Array Questions:"+s);
final TextView txtque = (TextView) findViewById(R.id.que_txt);
final String text=ques1.get(j).toString();
System.out.println("Array:"+text);
txtque.setText(text);
}
try {
int i = 0;
// answ1=new ArrayList<String>(new HashSet<String>(answ1));
JSONObject c = groups.getJSONObject(i);
String answer = c.getString(TAG_ANSW);
System.out.println("Checking ::"+answer);
answ=answer;
HashMap<String, String> map1 = new HashMap<String, String>();
answ1.add(answer);
System.out.println(" Answer array:"+answ1);
String[] answArr = new String [answ1.size()];
answArr = answ1.toArray(answArr);
for(String A: answArr){
Collections.sort(answ1, new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.compareToIgnoreCase(s2);
}
});
System.out.println("All Array Answers:"+A);
}
final TextView txtRadio = (TextView) findViewById(R.id.rdtxt);
btn_practicerg =(RadioGroup) findViewById(R.id.rdgroup);
btn_practice1 = (RadioButton) findViewById(R.id.RB1);
btn_practice1.setText(String.valueOf(answArr[0]));
btn_practice2 = (RadioButton) findViewById(R.id.RB2);
btn_practice2.setText(String.valueOf(answArr[1]));
btn_practice3 = (RadioButton) findViewById(R.id.RB3);
btn_practice3.setText(String.valueOf(answArr[2]));
btn_practice4 = (RadioButton) findViewById(R.id.RB4);
btn_practice4.setText(String.valueOf(answArr[3]));
btn_practicerg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
RadioButton checkedRadioButton = (RadioButton) findViewById(checkedId);
}
});
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
btn_practicerg.clearCheck();
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).toString());
k++;
btn_practice1.setText(answ1.get(k).toString());
k++;
btn_practice2.setText(answ1.get(k).toString());
k++;
btn_practice3.setText(answ1.get(k).toString());
k++;
btn_practice4.setText(answ1.get(k).toString());
}
});
}