button.setOnClickListener. error

后端 未结 2 969
情深已故
情深已故 2021-01-26 07:11

This is my code:

final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v)         


        
相关标签:
2条回答
  • 2021-01-26 07:54

    It's all in your code ? Or part of it?

    If your code is complete ? You should Add your code , Inside method oncreate();

    0 讨论(0)
  • 2021-01-26 07:56

    Your code has to be in a method, like onCreate.

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            }
        });
    }
    
    0 讨论(0)
提交回复
热议问题