[android-developers] A WebView inside of a fragment
I'm trying to get a hook to a WebView in my layout and it's coming back null each time. Can anyone tell me what I'm doing wrong here? WebViewFragment.java public class WebViewFragment extends Fragment { private View mContentView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContentView = inflater.inflate(R.layout.web_view_fragment, null); return mContentView; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webview = (WebView)mContentView.findViewById(R.id.webview); // use webview to set url... } } web_view_fragment.xml ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=http://schemas.android.com/apk/res/android; android:orientation=horizontal android:layout_width=match_parent android:layout_height=match_parent WebView android:id=@+id/webview android:layout_width=fill_parent android:layout_height=fill_parent android:layout_weight=2 / /LinearLayout -- Chris Stewart http://chriswstewart.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] A WebView inside of a fragment
Well, you can definitely use WebView in fragments: https://github.com/commonsguy/cw-android/tree/master/Fragments/EU4You_6 My best guess is that the fragment is not yet attached to the view hierarchy by then. Since you get the same Bundle in both places, you may just want to move your loadURL() or whatever call to onCreateView(). On Sun, Mar 20, 2011 at 10:25 AM, Chris Stewart cstewart...@gmail.com wrote: I'm trying to get a hook to a WebView in my layout and it's coming back null each time. Can anyone tell me what I'm doing wrong here? WebViewFragment.java public class WebViewFragment extends Fragment { private View mContentView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContentView = inflater.inflate(R.layout.web_view_fragment, null); return mContentView; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webview = (WebView)mContentView.findViewById(R.id.webview); // use webview to set url... } } web_view_fragment.xml ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=http://schemas.android.com/apk/res/android; android:orientation=horizontal android:layout_width=match_parent android:layout_height=match_parent WebView android:id=@+id/webview android:layout_width=fill_parent android:layout_height=fill_parent android:layout_weight=2 / /LinearLayout -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training...At Your Office: http://commonsware.com/training -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] A WebView inside of a fragment
Thanks for linking your example. I'm getting a reference to the WebView now with: WebView webview = (WebView)(getView().findViewById(R.id.webview)); It's not loading my web page just yet, but that's next. :o -- Chris Stewart http://chriswstewart.com On Sun, Mar 20, 2011 at 10:57 AM, Mark Murphy mmur...@commonsware.comwrote: Well, you can definitely use WebView in fragments: https://github.com/commonsguy/cw-android/tree/master/Fragments/EU4You_6 My best guess is that the fragment is not yet attached to the view hierarchy by then. Since you get the same Bundle in both places, you may just want to move your loadURL() or whatever call to onCreateView(). On Sun, Mar 20, 2011 at 10:25 AM, Chris Stewart cstewart...@gmail.com wrote: I'm trying to get a hook to a WebView in my layout and it's coming back null each time. Can anyone tell me what I'm doing wrong here? WebViewFragment.java public class WebViewFragment extends Fragment { private View mContentView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContentView = inflater.inflate(R.layout.web_view_fragment, null); return mContentView; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webview = (WebView)mContentView.findViewById(R.id.webview); // use webview to set url... } } web_view_fragment.xml ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=http://schemas.android.com/apk/res/android; android:orientation=horizontal android:layout_width=match_parent android:layout_height=match_parent WebView android:id=@+id/webview android:layout_width=fill_parent android:layout_height=fill_parent android:layout_weight=2 / /LinearLayout -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training...At Your Office: http://commonsware.com/training -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] A WebView inside of a fragment
So, apparently, having the Internet permission is kind of important for what I'm trying to do. :o It's been quite awhile since I've started an Android project from scratch... -- Chris Stewart http://chriswstewart.com On Sun, Mar 20, 2011 at 11:05 AM, Chris Stewart cstewart...@gmail.comwrote: Thanks for linking your example. I'm getting a reference to the WebView now with: WebView webview = (WebView)(getView().findViewById(R.id.webview)); It's not loading my web page just yet, but that's next. :o -- Chris Stewart http://chriswstewart.com On Sun, Mar 20, 2011 at 10:57 AM, Mark Murphy mmur...@commonsware.comwrote: Well, you can definitely use WebView in fragments: https://github.com/commonsguy/cw-android/tree/master/Fragments/EU4You_6 My best guess is that the fragment is not yet attached to the view hierarchy by then. Since you get the same Bundle in both places, you may just want to move your loadURL() or whatever call to onCreateView(). On Sun, Mar 20, 2011 at 10:25 AM, Chris Stewart cstewart...@gmail.com wrote: I'm trying to get a hook to a WebView in my layout and it's coming back null each time. Can anyone tell me what I'm doing wrong here? WebViewFragment.java public class WebViewFragment extends Fragment { private View mContentView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContentView = inflater.inflate(R.layout.web_view_fragment, null); return mContentView; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webview = (WebView)mContentView.findViewById(R.id.webview); // use webview to set url... } } web_view_fragment.xml ?xml version=1.0 encoding=utf-8? LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=horizontal android:layout_width=match_parent android:layout_height=match_parent WebView android:id=@+id/webview android:layout_width=fill_parent android:layout_height=fill_parent android:layout_weight=2 / /LinearLayout -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Android Training...At Your Office: http://commonsware.com/training -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en