這是ListView的如何從一個發送的ArrayList <HashMap中<字符串,對象>>的值到另一個活動
<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); }
但它是作爲工作的錯誤。當我使用它,我在新的活動所有的ArrayList
intent.putExtra("arraylist", Irr);
我需要的只有 「hm.put(Form3, 」3「);」 (正確地只有「3」值)在我的NewActivity。 幫助我正確組成它。
你的問題是什麼?將數據從一個「活動」轉移到另一個?或者創建一個新的「活動」? – owe
「將數據從一個活動傳輸到另一個」這是問題。新活動必須按照單元格中的「文本3」具有「文本3」。 – Ibir
「有問題」太模糊了。你必須描述你的問題或顯示你的錯誤。這裏是一個描述如何問:http://stackoverflow.com/questions/how-to-ask。 – owe