Issue
Hi everyone i am finding difficulty in accessing the file from my project assets folder. This is my xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androidhive.info.materialdesign.activity.HomeFragment"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<!--<TextView-->
<!--android:id="@+id/label"-->
<!--android:layout_alignParentTop="true"-->
<!--android:layout_marginTop="10dp"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:gravity="center_horizontal"-->
<!--android:textSize="30sp"-->
<!--android:text="About PES"-->
<!--android:textStyle="bold"/>-->
<!--<TextView-->
<!--android:layout_below="@id/label"-->
<!--android:layout_width="fill_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_marginTop="10dp"-->
<!--android:textColor="@color/text"-->
<!--android:text="@string/aboutpes"-->
<!--android:layout_centerHorizontal="true"-->
<!--android:textIsSelectable="true" />-->
<WebView android:id="@+id/webPage"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
This my fragment file
public class HomeFragment extends Fragment{
private WebView webView;
public HomeFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.fragment_home);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
webView = (WebView) rootView.findViewById(R.id.webPage);
// webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("file:///android_assets/programs.html");
// Inflate the layout for this fragment
return rootView;
}
public void onAttach(Activity activity) {
super.onAttach(activity);
}
public void onDetach() {
super.onDetach();
}
}
Would be grateful if somebody suggests me where i am going wrong. So that i can correct myself.
Solution
Try this
webView = (WebView) rootView.findViewById(R.id.webPage);
webView .setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView .loadUrl("file:///android_assets/programs.html");
Answered By - Neal Ahluvalia
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.