ListView的OnItemClickListener一个新的活动 [英] ListView OnItemClickListener with a new activity
本文介绍了ListView的OnItemClickListener一个新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个OnItemClickListener列表视图。当我点击一个项目,我想在一个新的活动像这样打开一个新的wiew:
I have a listView with an OnItemClickListener. When I am clicking on an item, I would like to open a new wiew in a new Activity like this:
final ListView lv1 = (ListView) findViewById(R.id.ListView02);
lv1.setAdapter(new SubmissionsListAdapter(this,searchResults));
lv1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent myIntent = new Intent(v.getContext(), UserSubmissionLog.class);
startActivityForResult(myIntent, 0);
UserSubmissionLog userSubmissionLogs= new UserSubmissionLog(position);
System.out.println("Position "+position);
}
}
);
现在的问题是,我要点击的位置号码转移到新的活动,不知道如何做到这一点。
The problem is that I have to transfer the clicked position number to the new activity and don't know how to do this.
感谢你。
推荐答案
您应该将它添加到意图:
You should add it to the intent:
Intent myIntent = new Intent(v.getContext(), UserSubmissionLog.class);
myIntent.putExtra("position", position);
startActivityForResult(myIntent, 0);
和新活动,请致电:
int prePosition = getIntent().getIntExtra("position", someDefaultIntValue);
这篇关于ListView的OnItemClickListener一个新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文