后的ListView的onClick,更改活动
问题描述:
这里是我的代码后的ListView的onClick,更改活动
this.getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent i = new Intent(this,lastview.class);
startActivity(i);
}
});
的“本”是一个ListActivity,但我希望下一个活动是一种正常的活动
,我的代码是错误的在这条线
Intent i = new Intent(this,lastview.class);
错误信息是
The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<lastview>) is undefined
我该如何解决它?
答
下面是示例代码。这会帮助你。
public class YourListActivity extends ListActivity {
private Context context;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
context =this;
.....
......
this.getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent i = new Intent(context,lastview.class);
// else you can use the code like below
//Intent i = new Intent(YourListActivity.this ,lastview.class);
startActivity(i);
}
});
}
答
改变这一行
Intent i = new Intent(this,lastview.class);
这样,你的活动改为MyListActivity
Intent i = new Intent(MyListActivity.this, lastview.class);
答
你也可以将它像:
startActivity(new Intent(Yourclass_name.this,lastview.class));
+0
问题解决^^ 但仍然感谢您的帮助^^ – bbbbbird1 2012-01-10 04:50:50
非常感谢^^ 的问题,通过你的答案解决 的感谢! – bbbbbird1 2012-01-10 04:48:56
欢迎bbbbbird1 ..... – 2012-01-10 04:56:04