【发布时间】:2014-02-25 06:02:24
【问题描述】:
这是列表视图
<LinearLayout
… >
<ListView
android:id="@+id/listView1" >
</ListView>
</LinearLayout>
还有 3 件物品在 сell
<TextView
android:id="@+id/text1" />
<TextView
android:id="@+id/text2" />
<Button
android:id="@+id/button1"/>
这是代码
public class Spisok extends Activity {
private ArrayList<HashMap<String, Object>> Irr;
private static final String Form1 = "form1"; // Форма1
private static final String Form2 = "form2"; // Форма2
private static final String Form3 = "form3"; // Форма3
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spisok);
setTitle("Irr");
ListView listView = (ListView) findViewById(R.id.listView1);
// создаем массив списков
Irr = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> hm;
hm = new HashMap<String, Object>();
hm.put(Form1, "1");
hm.put(Form2, "2");
hm.put(Form3, "3");
Irr.add(hm);
hm = new HashMap<String, Object>();
hm.put(Form1, "1");
hm.put(Form2, "2");
hm.put(Form3, "3");
Irr.add(hm);
SimpleAdapter adapter = new SimpleAdapter(this, Irr,
R.layout.list_item, new String[] { Form1, Form2, Form3 },
new int[] { R.id.text1, R.id.text2, R.id.text3 });
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<> arg0, View arg1, int arg2,
long arg3) {
Intent intent = new Intent(this, New.class);
intent.putExtra("arraylist", Irr);
startActivity
}
});
还有这个:
ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("arraylist");
TextView Info = (TextView)findViewById(R.id.text9);
Info.setText("view" +Irr); }
但这是错误的。使用的时候,我的新Activity里都有ArrayList
intent.putExtra("arraylist", Irr);
我只需要 "hm.put(Form3, "3");" (正确只有“3”值)在我的 NewActivity 中。 帮助我正确地组成它。
【问题讨论】:
-
你有什么问题?将数据从一个
Activity传输到另一个?还是创建一个新的Activity? -
"将数据从一个 Activity 传输到另一个" 这是问题。新活动必须具有“text3”,与单元格处的按钮一致。
-
“出了点问题”太含糊了。您必须描述您的问题或显示您的错误。以下是如何提问的说明:stackoverflow.com/questions/how-to-ask.
-
没有错误。只是这是错误的:intent.putExtra ("form3", Form3 );如何修正 put/get 价值?
标签: android-listview arraylist hashmap