点击图片按钮,进行跳转
btnAbout.setOnClickListener(new OnClickListener(){ public void onClick(View v) {
Intent intent=new Intent();
intent.setClass(this,main2.class);
startActivity(intent);
}
});
这段代码中对setclass报错,详情如下
The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (new View.OnClickListener(){}, Class<main2>)
求大神指点迷津
btnAbout.setOnClickListener(new OnClickListener(){ public void onClick(View v) {
Intent intent=new Intent();
intent.setClass(this,main2.class);
startActivity(intent);
}
});
这段代码中对setclass报错,详情如下
The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (new View.OnClickListener(){}, Class<main2>)
求大神指点迷津
你应该指定的是当前Activity.this
this指针的问题,你要正确理解this指针。
intent.setClass(this,main2.class);
--------------》》intent.setClass(TestClass.this,main2.class);
把里面的this改成你这个Activity.this就行了,如果只是一个this,它是指new View.OnClickListener(){},上面的错误提示里面已经说了
直接this的话是引用onClick的实例