这是我的代码
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);
}
});
“this”是ListActivity,但我希望下一个活动是正常活动
我的代码在这一行中是错误的
Intent i = new Intent(this,lastview.class);
错误信息是
The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<lastview>) is undefined
我该如何解决?
答案 0 :(得分:1)
更改此行
Intent i = new Intent(this,lastview.class);
像这样,将您的活动更改为MyListActivity
Intent i = new Intent( MyListActivity.this, lastview.class);
答案 1 :(得分:0)
你也可以这样写:
startActivity(new Intent(Yourclass_name.this,lastview.class));
答案 2 :(得分:0)
以下是示例代码。这将对您有所帮助。
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);
}
});
}