0

I tried so many times to change invisible a button visibility by loaded webview url.

I want to set invisible only if url equals "http://trscript.net/index.php". I printed url and it "http://trscript.net/index.php" but nothing change.

Code is here ;

 public class MainActivity extends Activity {
        Button refresh;

        protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              refresh=findViewById(R.id.refresh);
              myView = findViewById(R.id.web);

              myView.setWebViewClient(new WebViewClient() {
                                public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                                    myView.loadUrl("file:///android_asset/no.html");

                                }


                                @Override
                                public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                                    handler.proceed();
                                }



                                @Override
                                public void onPageFinished(WebView view, String url) {
                                    if(url=="http://trscript.net/index.php"){
                                        refresh.setVisibility(View.INVISIBLE);


                                    }
                                    else{
                                        refresh.setVisibility(View.VISIBLE);

                                    }
                                    dialog.dismiss();
                                }
                            }

}

bymerdo
  • 77
  • 1
  • 5
  • Possible duplicate of [How do I compare strings in Java?](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Bö macht Blau Jul 13 '19 at 12:46

1 Answers1

0

In java, when using == on two objects, you're not actually comparing the strings themselves. You'll need to use .equals(String).

== actually compares the two object's references, not their values.

string1.equals(String target) compares the two strings based off of the actual characters in the strings.

Please Replace your two string compare code with this code:

 if(url.equals("http://trscript.net/index.php")){
     refresh.setVisibility(View.INVISIBLE);
    }
Android Geek
  • 8,956
  • 2
  • 21
  • 35