朋友你好我使用的ListItem點擊程序列表視圖執行波紋管代碼,但它有很多的ListItem將調用不同的網頁 先後爲不同的網頁,我有列表視圖創建不同的Fragment.xml和Framgment.java文件?或者我可以保留一個共同的片段和XML文件,並在列表項狀態的幫助下,我可以調用不同的網頁! 請幫助我這個 因爲我初學的Android 謝謝如何保持一個片段查看多個網頁
fragment.xml之
<!-- TODO: Update blank fragment layout -->
<WebView
android:id="@+id/webViewabout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Fragment.java
package com.ft.bscit;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import com.ft.bscit.R;
/**
* A simple {@link Fragment} subclass.
*/
public class About_bscit_Fragment extends Fragment {
public About_bscit_Fragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_about_bscit, container, false);
WebView webView = (WebView)rootView.findViewById(R.id.webViewabout);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///android_asset/index.html");
return rootView;
}
}
你在哪裏實例化你的片段?粘貼該代碼。 –
已在下面的答案部分發布了片段實例化 – Vitesh