我在 Activity 中使用 ListView。 在任何选择的列表项(ID)上,它应该在另一个 Activity 中显示整行(与 ID 相关联)。 我使用 bundle 对象通过“putExtra”传递长值。但这也不起作用。我可以知道如何完成它吗?
第一个 Activity :
Bundle dataBundle = new Bundle();
dataBundle.putLong("ID",id);
Intent myIntent = new Intent();
myIntent.setClassName("com.mink7.databaseapplication", "com.mink7.databaseapplication.OnItemClickFromLV");
myIntent.putExtras(dataBundle);
startActivity(myIntent);
第二个 Activity :
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
long idd = extras.getLong("ID",0);
Cursor c=db.getName(idd);
final String name_ret = c.getString(c.getColumnIndex("name"));
final int age_ret = Integer.valueOf(c.getString(c.getColumnIndex("age")));
final String city_ret = c.getString(c.getColumnIndex("city"));
t1.setText(name_ret);
t2.setText(age_ret);
t3.setText(city_ret);
}
最佳答案
直接加上long就可以了,像intent.putExtra("ID",value)
extras已经是键值对了。那么用于接收第二个 Activity 的值的代码应该可以正常工作。
关于android - 如何将长期值(value)从一项 Activity 发送到另一项 Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13135505/