嗨,大家好,我有一個問題。 如何在Fragment
內使用WebView
? 我知道如何在Activity
中使用WebView
,但我不知道如何在Fragment
中執行此操作。 因爲在Fragment
中不能使用FindViewById
。如何在片段l中使用WebView?
感謝您的幫助
弗洛帝國
嗨,大家好,我有一個問題。 如何在Fragment
內使用WebView
? 我知道如何在Activity
中使用WebView
,但我不知道如何在Fragment
中執行此操作。 因爲在Fragment
中不能使用FindViewById
。如何在片段l中使用WebView?
感謝您的幫助
弗洛帝國
你必須讓你的onCreateView
這樣
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
View v = layoutInflater.inflate(R.layout.my_fragment, container, false);
WebView webview = (WebView) v.findViewById(R.id.webview_id);
// other stuff
return v;
}
謝謝你幫助我:-)祝你有美好的一天 –
您可以使用findViewById()
方法片段。例如,在onCreateView方法:
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, Bundle savedInstanceState) {
View fragmentView = layoutInflater.inflate(R.layout.your_fragment, container, false);
// and you can use findViewById() method on fragmentView
View v = fragmentView.findViewById(R.id.your_view);
...
return fragmentView;
}
希望,它幫助。
非常感謝你。祝你有美好的一天 –
歡迎堆棧溢出。請看[問]。 –
請回答我的問題 –