Issue
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();
}
}
}
Solution
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);
}
Answered By - Android Geek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.