无法从按钮动作侦听器启动活动?
我尝试启动一个 Activity,但它给了我错误消息:The method startActivity(Intent) is undefined for the type new View.onClickListener(){}
这是我使用 startActivity 的代码。
place.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO If placeButton was clicked:
Intent placepin = new Intent("my.locations.oskar.mendel.PLACEPINACTIVITY");
startActivity(placepin);
}
});
I tried to start an activity but it gives me the error message: The method startActivity(Intent) is undefined for the type new View.onClickListener(){}
Here is the code i used the startActivity in.
place.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO If placeButton was clicked:
Intent placepin = new Intent("my.locations.oskar.mendel.PLACEPINACTIVITY");
startActivity(placepin);
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
OnClickListener 是 Activity 类中的一个对象。在 onClick 代码块中,Activity 的继承方法对 OnClickListener 对象不可见,因此您需要相应地调整范围。你可能想要这样的东西:
The OnClickListener is an object within your Activity class. Within the onClick codeblock, the Activity's inherited methods are not going to be visible to the OnClickListener object, hence you will need to adjust the scope accordingly. You likely want something like this:
我解决这个问题的方法是使用布尔值。
希望这对你有帮助。
My method into solving this problem is use boolean value.
hopefully that helps you.