Fragment webview javascript function is not working

后端 未结 2 585
谎友^
谎友^ 2020-12-22 01:20

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         


        
相关标签:
2条回答
  • 2020-12-22 01:53

    Change your fragment to this,

    public static class TabFragmentClass extends Fragment
    {   
       private static CustomWebView webview=null;
       private static boolean isInitialized=false;
     @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
           try
           {
               linearLayout=new LinearLayout(sActiveContext);
               linearLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); 
               linearLayout.setOrientation(LinearLayout.VERTICAL);
               webview=new CustomWebView(sActiveContext);
               FrameLayout layout=webview.createwebview();
               onLoadWebview();
               linearLayout.addView(layout);
               linearLayout.setId(sActionBar.getSelectedTab().getPosition());
               return linearLayout;
            }
            catch(Exception error)
            {
                System.out.println(error.getMessage());
                return null;
            }
    
     }
    @Override
    public void onActivityCreated()
    {
    super.onActivityCreated();
    isInitialized=true;
    }
    @Override
    public void onResume()
    {
    if(isInitialized)
        onLoadWebView();
    }
    public void onLoadWebview()
    {
    for (int i = 0; i < arrayList.size(); i++) {
                   if(sActionBar.getSelectedTab().getPosition()==i)
                   {
                       webview.initwebview(arrayList.get(i));
                       mWebViewList.add(i, webview);
                       break;
                   }
               }
    }
       }
    
    0 讨论(0)
  • 2020-12-22 01:53

    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

    0 讨论(0)
提交回复
热议问题