我正在制作一个应用程序,该应用程序使用具有 2 个 View 的 Android 应用程序从 Web 服务接收数据。
首先询问登录名和密码。然后向 web 服务请求 Activity ,如果有数据,他创建一个在 ListView 中显示数据的 Intent :
主要
private ArrayList accountlist = new ArrayList();
...
accountlist.add(...)
...
Intent intent = new Intent(Main.this, Second.class);
intent.putExtra("accountlist", accountlist);
intent.putExtra("login", loginEditText.getText().toString());
intent.putExtra("pass", passwordEditText.getText().toString());
startActivity(intent);
第二
private ArrayList accountlist;
...
public void onCreate(Bundle savedInstanceState) {
...
setListAdapter(new ArrayAdapter<String>(this, R.layout.results,accountlist));
...
}
private void refresh() {
...
accountlist.add(...)
setListAdapter(new ArrayAdapter<String>(this, R.layout.results,accountlist));
}
结果是我有添加到当前列表中的项目(例如,我有 2 个项目,如果我刷新 4 次,我将在 View 中有 10 个项目,我只需要最后 2 个)
如果你有想法:D
最佳答案
您不能在 Activity 之间直接传递 ArrayList,您必须通过序列化转到某种对象。读这个:How do I pass an object from one activity to another on Android?
关于java - 在第二个 Intent 中刷新数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10709530/