saxパーサーを使用してデータを正常に解析し、logcatに出力が正しく表示されますが、そのデータを体系的に配置する必要があります。しかし、問題は私の質問の長さとインデックスが2であるため、オプションも2になります。代わりに、質問ごとに4になります。提案してください
コードスニペットは
for (int i = 0; i < categorylist.getTitle().size(); i++) {
TableRow tr = new TableRow(this);
tr.setPadding(2, 2, 2, 2);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.FILL_PARENT);
int leftMargin=0;
int topMargin=2;
int rightMargin=0;
int bottomMargin=1;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(tableRowParams);
name[i]= new TextView(this);
name[i].setText(categorylist.getTitle().get(i));
name[i].setTextColor(Color.WHITE);
name[i].setTextSize(12);
name[i].setPadding(10,0,0,0);
name[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
tr.addView(name[i]);
t1.addView(tr, tableRowParams);
LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
rad1[i]= new RadioButton(this);
rad1[i].setText(categorylist.getValue().get(i));
rad1[i].setTextColor(Color.WHITE);
rad1[i].setTextSize(12);
rad1[i].setPadding(10,0,0,0);
rad1[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
rgrp.addView(rad1[i], 0, layoutParams);
}
xmlは
<Values>
<Question>
<Description><![CDATA[Some Question]]></Description>
<Options>
<option value="correct"><![CDATA[All of these]]></option>
<option value="incorrect"><![CDATA[Ok]]></option>
<option value="incorrect"><![CDATA[Fine]]></option>
<option value="incorrect"><![CDATA[Good one]]></option>
</Options>
</Question>
</Values>
logcatの出力は次のとおりです。
05-14 15:22:27.228: INFO/This is the title:(559): Which of the following are called celestial bodies?
05-14 15:22:27.248: INFO/This is the option:(559): All of these
05-14 15:22:27.248: INFO/This is the option:(559): Sun
05-14 15:22:27.248: INFO/This is the option:(559): Planets
05-14 15:22:27.248: INFO/This is the option:(559): Moon
05-14 15:22:27.258: INFO/This is the title:(559): In our solar system, _________ planets revolve around the Sun.
05-14 15:22:27.258: INFO/This is the option:(559): eight
05-14 15:22:27.258: INFO/This is the option:(559): five
05-14 15:22:27.258: INFO/This is the option:(559): ten
05-14 15:22:27.258: INFO/This is the option:(559): nine