Moving Android Activity Between Screens

Asked 2 years ago, Updated 2 years ago, 23 views

findViewById(R.id.Closeinfor).setOnClickListener(this); }

public void Inforclose (View view){
    switch (view.getId()){
        case R.id.Closeinfor :
            this.finish();
            break;
    }

There is an error in the part where findViewById used this, how can I get rid of the error?

What we are currently trying to develop is to press the close button to return to the previous activity. Closeinfor is the id of the button that closes the information window.

android

2022-09-22 12:20

1 Answers

This is a keyword that refers to the current object (self). If an error occurred in this.finish() because this object is not an activity. Please change the code by writing the corresponding activity (class name) as shown below.

SomeActivity.this.finish();

With a simple tip, type this in the Android studio and take a . to display an auto-complete list of the fields and functions available for that object. Check the list to see if there is a finish() function. (=The process of verifying that this object is an activity)


2022-09-22 12:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.