【发布时间】:2017-11-11 08:29:48
【问题描述】:
我在 Fragment 中的 webview 有问题。当我执行应用程序时,webview 不显示 Html 页面。这是我的代码:
public class BingMapFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private View main_view;
private static View v;
private WebView webMapView;
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
ListView lv;
TraceAdapter aAdpt;
private FragmentChangeActivity parent;
private OnFragmentInteractionListener mListener;
public BingMapFragment() {
// Required empty public constructor
setRetainInstance(true);
}
// TODO: Rename and change types and number of parameters
public static BingMapFragment newInstance(String param1, String param2) {
BingMapFragment fragment = new BingMapFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
webMapView = (WebView)main_view.findViewById(R.id.bingMapView);
webMapView.setWebViewClient(new WebViewClient());
WebSettings ws = webMapView.getSettings();
ws.setJavaScriptEnabled(true);
webMapView.loadUrl("file:///android_asset/prova.html");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
new DataSourceDeviceRealTime().getDeviceRealTime(this);
main_view = inflater.inflate(R.layout.fragment_bing_map,container,false);
v=main_view;
parent=(FragmentChangeActivity) getActivity();
parent.setupActionBar(Constants.SCREEN_MAP);
return inflater.inflate(R.layout.fragment_bing_map, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
public void goBack() {
if(GlobalData.isSalesforcePolicyActive() || GlobalData.isMobileRoutePolicyActive()){
parent.switchContent(new MenuFragment(), true);
} else {
parent.logoutButtonClicked();
}
}
}
我不知道问题的根源,因为我已经在另一个应用程序中使用了 webview。谢谢你的回复。
【问题讨论】:
标签: android android-studio android-fragments webview