【发布时间】:2019-02-27 12:56:34
【问题描述】:
我创建了第二个 Activity 来显示 ArrayList 中的所有元素。例如,如果 ArrayList 在 MainActivity 中包含以下内容:
//This is an Object type
thingsList = ["This is list1","This is list2"];
Intent intent = new Intent(this, Activity2.class);
Bundle b = new Bundle;
b.putString("Lists", thingsList.toString());
intent.putExtras(b);
startActivity(intent);
我的 Activity2.java 中有这个
ListView newListView = (ListView)findViewById(R.id.newListView);
Bundle b = getIntent().getExtras();
String newList = b.getString("Lists");
ArrayAdapter adapterList = new ArrayAdapter(this, R.layout.list_label, Collections.singletonList(newList));
newListView.setAdapter(adapterList);
它现在做的是:
[This is list1, This is list2]
如何循环遍历数组列表并使其显示在不同的行上
This is list1
This is list2
我试过这样做,但没有成功
thingsList = ["This is list 1","This is list 2"];
Intent intent = new Intent(this, Activity2.class);
Bundle b = new Bundle;
for (Object makeList: thingsList) {
b.putString("Lists", makeList.toString());
intent.putExtras(b);
}
startActivity(intent);
它所做的只是抓取数组列表中的最后一个元素,例如
This is list2
提前致谢,不知道这个问题是否有意义。
【问题讨论】:
标签: java android listview arraylist