我想创建一个按钮,点击后它会显示另一个意图。setOnClickListener错误 - 无法解析符号
这是代码:
<Button
android:text="Bine ati venit!"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/button1"
android:background="#479fc7"
android:textSize="40dp"
android:textColor="@color/colorPrimaryDark"
android:textStyle="normal|bold|italic"
android:textAllCaps="false"
android:fontFamily="casual"
android:onClick="next_page"/>
,并从的.java类:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
}
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick (View v){
next_page(v);
}
});
public void next_page(View v) {
Intent intent = new Intent(this, MapsActivity.class);
startActivity(intent);
}
我得到的错误: “无法解析符号 'setOnClickListener'”,“可变的onClick是永远使用“,”;预计“....
你为什么不把'onCreate'方法中的'button'? –
你已经在你的xml文件中设置了标签android:onClick =“next_page”,所以你可以删除你的Button init,它的onClickListener –
哦,我没有看到...... thx! – rocko