我的问题如下。我希望能够将文本文件读入数组适配器。我有一个TextView和3个RadioButtons。到目前为止,我已设法传递一个字符串数组,可用于更新TextView。我有一个数组列表,如下所示
ArrayList<info> list = new ArrayList<info>();
for(int i=1; i <= 3; i++)
{
Reader reader = new ResultsReader("C:/Users/ALEXDEV/workspace/Questions/src/quiz"+i+".txt");
reader.read();
String str = ((ResultsReader)reader).getInput();
String data[] = str.split("<.>");
info = q new info();
q.question = data[0];
q.choice1 = data[2];
q.choice2 = data[3];
q.choice3 = data[4];
list.add(q);
}
for(Question qs: list) {
System.out.println("Q: "+qs.question);
System.out.println("Q: "+qs.choice1);
System.out.println("Q: "+qs.choice2);
System.out.println("Q: "+qs.choice3);
}
-
问:问题是 问:回答一句 问:回答二 问:回答三个所以我想要todo是将arraylist传递给arrayadapter所以我可以使用getView方法返回各种结果
到目前为止,我已经尝试将列表作为arraylist传递给MySimpleArrayAdapter适配器= new MySimpleArrayAdapter(this,list);
公共类CustomAdapter扩展了ArrayAdapter {
private ArrayList<Question> list;
private Context context;
public CustomAdapter(Context context, int textViewResourceId, ArrayList<Question> list) {
super(context, textViewResourceId,list);
this.context = context;
this.list = list;
// TODO Auto-generated constructor stub
}
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.basic, null);
}
Question element = list.get(position);
if (element!= null) {
// My layout has only one TextView
TextView itemView = (TextView) view.findViewById(R.id.questionText);
if (itemView != null) {
// do whatever you want with your string and long
itemView.setText(String.format("%s %d", element.question, element.answer));
}
}
return view;
}
答案 0 :(得分:0)