delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

mWebView.setListener(this,this); error:- can not resolve method. #272

Closed mhemon closed 3 years ago

mhemon commented 3 years ago

// in the androidx Fragment (androidx.fragment.app.Fragment)

mWebView.setListener(this,this);

give error.. and also how to handle OnBackpress in the Fragment? seems you didn't mention that. i was trying to Achive mWebView.canGoBack(); but it's didn't work.

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // This callback will only be called when MyFragment is at least Started.
        OnBackPressedCallback callback = new OnBackPressedCallback(true /* enabled by default */) {
            @Override
            public void handleOnBackPressed() {
                // Handle the back button event
                mWebView.canGoBack();
            }
        };
        requireActivity().getOnBackPressedDispatcher().addCallback(this, callback);
        callback.isEnabled();
    }
 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_feed2, container, false);
        String data = Prefs.getString("WEB", defaulturl);
        mWebView = (AdvancedWebView) view.findViewById(R.id.webview);
        mWebView.setListener(this,this);
        mWebView.setMixedContentAllowed(true);
        mWebView.loadUrl(data);
        return view;
    }

if possible then add a sample app with Fragment in Source Folder in the Master branch.

ocram commented 3 years ago

For androidx.fragment.app.Fragment, you should be able to replace mWebView.setListener(this, this); with mWebView.setListener(getActivity(), this);, as shown in the README, or even mWebView.setListener(getActivity(), getActivity());.

Does that work?

mhemon commented 3 years ago

Found a solution to handle on back press.. OnBackPressedCallback callback = new OnBackPressedCallback(true /* enabled by default */) { @Override public void handleOnBackPressed() { if (!mWebView.onBackPressed()) { return; } remove(); } }; requireActivity().getOnBackPressedDispatcher().addCallback(this, callback);

developerGM commented 3 years ago

@mhemon the problem is that the library use android.fragment.app.Fragment and your project probably use androidx.fragment.app.Fragment so the listener mWebView.setListener(this, this); cannot works

@ocram please update your library to androidx

mhemon commented 3 years ago

@developerGM yes, ur right.

developerGM commented 3 years ago

@mhemon will there be an update of this library?

mhemon commented 3 years ago

@ocram plz tell us, is there any update Coming up.