Mar*_*ark 10 android android-activity
我有两个java文件.在第一个我有我的活动,从应用程序启动时开始.第二个叫做"AuswahlActivity.java"和xml文件"auswahl.xml".我有这个代码到AuswahlActivity.java:
public class AuswahlActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.auswahl);
//Your code here
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想开始这样的活动:
Intent myIntent = new Intent(this, AuswahlActivity.class);
this.startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误消息 The constructor Intent(new View.OnClickListener(){}, Class<AuswahlActivity>) is undefined
我该如何工作?
st0*_*0le 21
Intent myIntent = new Intent(this, AuswahlActivity.class);
this.startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)
这部分代码可能位于a OnClickListener
,只需使用
Intent myIntent = new Intent(YouCurrentActivity.this, AuswahlActivity.class);
YouCurrentActivity.this.startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)
原因是,在一个匿名类(你的OnClickListener)中this
引用Onclicklistener而不是活动...... Intent的第一个参数是Context(应该是活动),因此是错误.
归档时间: |
|
查看次数: |
12988 次 |
最近记录: |