Skip to content Skip to sidebar Skip to footer

Fragment Webview Java Script Function Is Not Working

I have dynamically created the action bar and tabs. I have define a class for tab fragments like the below code. public static class TabFragmentClass extends Fragment { @Overri

Solution 1:

Change your fragment to this,

publicstaticclassTabFragmentClassextendsFragment
{   
   privatestaticCustomWebView webview=null;
   privatestaticboolean isInitialized=false;
 @OverridepublicViewonCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stubtry
       {
           linearLayout=newLinearLayout(sActiveContext);
           linearLayout.setLayoutParams(newLayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
           linearLayout.setOrientation(LinearLayout.VERTICAL);
           webview=newCustomWebView(sActiveContext);
           FrameLayout layout=webview.createwebview();
           onLoadWebview();
           linearLayout.addView(layout);
           linearLayout.setId(sActionBar.getSelectedTab().getPosition());
           return linearLayout;
        }
        catch(Exception error)
        {
            System.out.println(error.getMessage());
            returnnull;
        }

 }
@OverridepublicvoidonActivityCreated()
{
super.onActivityCreated();
isInitialized=true;
}
@OverridepublicvoidonResume()
{
if(isInitialized)
    onLoadWebView();
}
publicvoidonLoadWebview()
{
for (int i = 0; i < arrayList.size(); i++) {
               if(sActionBar.getSelectedTab().getPosition()==i)
               {
                   webview.initwebview(arrayList.get(i));
                   mWebViewList.add(i, webview);
                   break;
               }
           }
}
   }

Solution 2:

onCreateView only will be create Once ONLY after Activity Created You can put your method in onResume() or refresh web You can see the Fragment's life circle here

Post a Comment for "Fragment Webview Java Script Function Is Not Working"