如何把一个listview中选中的值展示到另外一个 activity中
1个回答
展开全部
处理方法
First Activity的代码:
[html] view plaincopy
+@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
// txt.setText(items[position]);
// Try to send the items[position] in the intent
Intent i = new Intent(this, SecondActivity.class);
i.putExtra("testonArray", items[position].toString());
startActivity(i);
}
第二个activity代码
[html] view plaincopy
Bundle extras=getIntent().getExtras();
String selected_item=extras.getString("testonArray");
txt = (TextView) findViewById (R.id.txt2);
txt.setText(selected_item);
First Activity的代码:
[html] view plaincopy
+@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
// txt.setText(items[position]);
// Try to send the items[position] in the intent
Intent i = new Intent(this, SecondActivity.class);
i.putExtra("testonArray", items[position].toString());
startActivity(i);
}
第二个activity代码
[html] view plaincopy
Bundle extras=getIntent().getExtras();
String selected_item=extras.getString("testonArray");
txt = (TextView) findViewById (R.id.txt2);
txt.setText(selected_item);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询