【发布时间】:2014-08-10 00:37:11
【问题描述】:
我正在尝试将列表数组的数据发送到另一个活动中的数组适配器。这是基于一个微笑计数器应用程序,当我打开第二个活动时,它会显示哪些按钮已被按下以及按下了多少次。
到目前为止,我已经创建了我的数组列表第一个活动
String player1data = lifepointsP1.getText().toString();
ArrayList<String> myList1 = new ArrayList<String>();
myList1.add(player1data);
并且每次更改 lifepointsP1 文本时都会更新。然后按下按钮打开新活动,我这样做:
Intent mi = new Intent(v.getContext(), MatchHistory.class);
mi.putExtra("p1L", myList1);
startActivity(mi);
将数据发送到第二个活动,然后我像这样检索它:
String p1List = (getIntent().getStringExtra("p1L"));
然后我创建我的数组适配器并将该字符串作为值插入:
lvP1 = (ListView) findViewById(R.id.lvP1R);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MatchHistory.this, android.R.layout.simple_list_item_1, p1List);
lvP1.setAdapter(arrayAdapter);
尽管如此,这给了我一个错误,并告诉我从 arrayadapter 参数中取出“p1List”字符串。我不知道它为什么这样做。
【问题讨论】:
标签: android arrays listview arraylist android-arrayadapter