片段的WebView Java脚本功能无法正常工作 [英] Fragment webview java script function is not working
问题描述
我已经动态创建操作栏和标签。我有喜欢跌破code标签片段定义一个类。
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
{
@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);
CustomWebView webview=new CustomWebView(sActiveContext);
FrameLayout layout=webview.createwebview();
for (int i = 0; i < arrayList.size(); i++) {
if(sActionBar.getSelectedTab().getPosition()==i)
{
webview.initwebview(arrayList.get(i));
mWebViewList.add(i, webview);
break;
}
}
linearLayout.addView(layout);
linearLayout.setId(sActionBar.getSelectedTab().getPosition());
return linearLayout;
}
catch(Exception error)
{
System.out.println(error.getMessage());
return null;
}
}
}
网址是具有自己的本地Java方法调用本地HTML文件。如果我选择的动作栏选项卡的第一次,这是做工精细。这是原生的Java方法正确调用和回调是成功的。如果我访问的标签第二次,该片段只显示,不重新创建选项卡的内容。 我需要的标签内容每次不创建功能。但我面临的不是定义的本地方法的错误的问题。这是本机方法不叫在所有。如何解决这个问题?
The url is the local html file having their own native java method calls. If I am select the action bar tab first time, this is working fine. That is native java method is correctly called and callback is success. If I am visiting the tab second time, the fragment is only shown, tabs content is not re-created. I need the functionality of tab content not created each time. But I am facing the issue of native method not defined error. That is the native method is not called at all. How can I fix the issue?
推荐答案
更改您的片段此,
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;
}
}
}
}
这篇关于片段的WebView Java脚本功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!