English 中文(简体)
在第二个意图中刷新一个阵列列表
原标题:refresh an arraylist in the second intent

我制作一个应用程序,接收来自网络服务的数据, 使用有两种视图的机器人应用程序。

第一个询问登录和密码。 然后活动请求网络服务, 如果有数据, 他将创建一个意图, 显示列表视图中的数据 :

主要主要

private ArrayList accountlist = new ArrayList();
...
accountlist.add(...)
...
Intent intent = new Intent(主要主要.this, 第二届.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));
}

结果是,我拥有目前清单中增列的项目(例如,我有两个项目,如果我刷新4次,我会有10个项目在视图中,我只有最后2个项目)

如果你有想法的话:D

最佳回答

好吧,我刚刚用了

accountlist.clear();

仅次于

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);

以清除将重新用来发射意图的清单!

问题回答

您无法在活动之间直接通过一个阵列列表, 您必须通过序列化方式进入对象类型 。 读此 : < a href="https:// stackoverflow. com/ questions/ 2906925/and - how- do- pass- i- pass- a- object- from- one- active- to- an- an- an- an- an- object - from- one- active- an- an- an- an- an- an- an- other > '我如何在 Android上从一个活动向另一个活动传递对象?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签