Reputation: 103
So I have a webview element in my main class, and I want to change its visibility to hidden, All I need is a total of it:
myWebView.setVisibility(View.GONE);
But my problem is when I want to control it from another class, I searched a lot on the internet and could not find a satisfactory answer, Here's what I tried:
MassegeNetsActivity.java: (main activity)
fullScreenFu.openFullScreen(MassegeNetsActivity.this);
fullScreenFu.java:
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
public class videoFullScreen extends AppCompatActivity {
public void openFullScreen(Context c) {
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setVisibility(View.GONE);
}
}
But when I call the function nothing happens, there is no error but it just does not respond, and the webview continues to be displayed. Of course this is a question that is also relevant to the image button or text, for me it came out with a webview :)
Thank you very much!
Upvotes: 1
Views: 161
Reputation: 103
So after using @Wongani I was able to do something that would work well, so it should be like this:
Step One We will define the browser as a class type in main class:
public static Webview myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_one);
myWebView = (Webview) findViewById(R.id.myWebView);
}
second level: We can now call him from the second class, like this:
MainActivity.myWebView.setVisibility(View.GONE);
it's very simply:)
good luck!
Upvotes: 0
Reputation: 39
create your webview as a class variable and initialize it in your onCreate method so that when you want to hide it, you just call the class variable instead of finding it by id every time
Upvotes: 2