我有一个多维arrayList.eg
arrayList 0 --> {startdate, duration, status}
1 --> {startdate, duration, status}
2 --> {startdate, duration, status}
我已经捆绑了这个数组并将其发送到下一个 Activity。在这个活动中,我可以将 arrayList 的第一个索引传递给适配器并显示数据(虽然它显示了 5 次而不是一次,但另一个问题)。
我的问题是如何将多个数组传递给适配器或让适配器迭代多个数组?
在下面的片段数组中是多维数组。我已经硬编码了 position(0) 以传递给适配器。我如何将内部的其他 7 个数组传递给适配器。
public class GetRota extends Activity {
private static final String TAG = GetRota.class.getSimpleName();
ListView listView;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.getrotalayout);
listView = (ListView)findViewById(R.id.rotalist);
intent = this.getIntent();
Bundle bundle = intent.getBundleExtra("rotaArrayBundle");
@SuppressWarnings("unchecked")
ArrayList array = (ArrayList) bundle.get("rotaArray");
String record = array.get(0).toString();
String[] itemsInRecord = record.split(",");
String[] recordItem = new String[5];
for(int x = 0; x < itemsInRecord.length; x++){
Log.e(TAG, "token = " + itemsInRecord[x]);
recordItem[x] = itemsInRecord[x];
}
MySimpleArrayAdapter arrayAdapter = new MySimpleArrayAdapter(this, recordItem);
listView.setAdapter(arrayAdapter);
}// end of onCreate
private class MySimpleArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MySimpleArrayAdapter(Context context, String[] values) {
super(context, R.layout.rotarowlayout, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rotarowlayout, parent, false);
TextView startTime = (TextView)rowView.findViewById(R.id.rowstarttime);
TextView duration = (TextView)rowView.findViewById(R.id.rowduration);
TextView status = (TextView)rowView.findViewById(R.id.rowstatus);
TextView name = (TextView)rowView.findViewById(R.id.rowclientname);
startTime.setText("Start Time: " + values[0]);
duration.setText("Duration:" + values[1]);
status.setText("Status:" + values[2]);
name.setText("Client:" + values[3] + values[4]);
return rowView;
}
}
}// end of GetRota