开发者

Bluetooth onClickView error

This is a snipet of code from my main activity, An error is showing up and i don't understand whats wrong?

The error is: void is an invalid type for the variable onClick.

I'm new to android and java so it may be kind of simple.. Thanks.

private void startApp(){

        View Patient_Button = findViewById(R.id.patientButton);
        Patient_Button.setOnClickListener(this);
        View Doctor_Button = findViewById(R.id.doctorButton);
        Doctor_Button.setOnClickListener(this);
        View About_Option = findViewById(R.id.aboutButton);
        About_Option.setOnClickListener(this);
        View Exit_Option = findViewById(R.id.exit);
        Exit_Option.setOnClickListener(this);

Error:        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.patientButton:
                Intent b = new Intent(this, Detailed_ModeActivity.class);
                startActivity(b);
                break;
            case R.id.doctorButton:
                Intent a = new Intent(this, Detailed_ModeActivity.class);
                startActivity(a);
                break;
            case R.id.aboutButton:
               开发者_如何学C Intent i = new Intent(this, About.class);
                startActivity(i);
                break;
            case R.id.exit:
                finish();
                break;
            }

        };

    }

I know that the error has something to do with the void but It ussually worked before


move onClick out of startApp :)

private void startApp(){

    View Patient_Button = findViewById(R.id.patientButton);
    Patient_Button.setOnClickListener(this);
    View Doctor_Button = findViewById(R.id.doctorButton);
    Doctor_Button.setOnClickListener(this);
    View About_Option = findViewById(R.id.aboutButton);
    About_Option.setOnClickListener(this);
    View Exit_Option = findViewById(R.id.exit);
    Exit_Option.setOnClickListener(this);
}

 public void onClick(View v) {
        switch (v.getId()) {
        case R.id.patientButton:
            Intent b = new Intent(this, Detailed_ModeActivity.class);
            startActivity(b);
            break;
        case R.id.doctorButton:
            Intent a = new Intent(this, Detailed_ModeActivity.class);
            startActivity(a);
            break;
        case R.id.aboutButton:
            Intent i = new Intent(this, About.class);
            startActivity(i);
            break;
        case R.id.exit:
            finish();
            break;
        }

 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜