我有这个 Intent 代码:
Intent arbeiten = new Intent(this, arbeiten.class);
startActivity(arbeiten);
但 Eclipse 告诉我:
The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<arbeiten>) is undefined
同一项目中的其他(工作) Intent ,但其他类看起来像
Intent toolb = new Intent(this, ToolBox.class);
toolb.putExtra("json", json.toString());
startActivity(toolb);
他们正在工作......
“Arbeiten”类看起来像这样:
package XXX;
import android.app.Activity;
import android.os.Bundle;
public class arbeiten extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
最佳答案
这是因为 this
引用了您的 OnItemClickListener
。有不同的方法可以解决这个问题。一种方法是像这样引用 Activity 的上下文:
Context mContext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//your code
mContext = this;
}
然后在您的 OnClickListener
中,将其更改为:
Intent arbeiten = new Intent(mContext, arbeiten.class);
startActivity(arbeiten);
关于java - Intent 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10517891/