在这里,我给出了一个示例,假设您有用户列表并单击要显示用户个人资料的项目...
在 List_Act 活动中...
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = mInflater.inflate(R.layout.rowitem,parent,false);
convertView.setTag(UserId);
}
private OnItemClickListener mlist = new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent i=new Intent(List_Act.this, Profile_Act.class);
int UserId = ((View)v.getParent()).getTag();
i.putExtra("UserId", UserId); //Setting variable you want to pass to another activity
startActivity(i);
}
};
在 onCreate() 的 Profile_Act 活动中
String UserId = getIntent().getExtras().getString("UserId"); //retrieving value in another activity
现在您将设置 UserId 变量,您可以使用它...