ANDROID ,如何从一个ACTIVITY中的列表LISTVIEW获取所选的列表内容传到另一个ACTIVITY页面中,

最好要有个例子,简单点,没分了
2025-01-02 23:55:41
推荐回答(1个)
回答1:

//定交一个listview
ListView lv=(ListView)findViewById(R.id.ListView01);
//数据源绑定
SimpleAdapter adp = new SimpleAdapter(this,
list, R.layout.main_list,
new String[]{"OrderType","Orderdate","Price","OrderState","Id"},
new int[]{R.id.tvTitle,R.id.tvDate,R.id.tvPrice,R.id.tvState,R.id.tvId});
//显示数据
lv.setAdapter(adp);
//item点事件
lv.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2,long arg3) {
Intent intent = new Intent(OrderActivity.this,DaiActivity.class);//OrderActivity.this,当前页面,DaiActivity.class转至的页面
//item内的数据保存在map中
Map map = (Map)lv.getItemAtPosition(arg2);
//需要的数据在intent中
intent.putExtra("id", map.get("Id"));
//跳转页面
OrderActivity.this.startActivity(intent);
}
});
另一个页面
Intent intent = getIntent();
String id = intent.getStringExtra("id");