小编roc*_*cko的帖子

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"/>
Run Code Online (Sandbox Code Playgroud)

以及来自 .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);
}
Run Code Online (Sandbox Code Playgroud)

我收到错误:“无法解析符号‘setOnClickListener’”、“变量 onClick 从未使用”、“;预期”...

android button android-intent

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

android ×1

android-intent ×1

button ×1