你好我有2个下拉。首先下拉[Spinner1]有4个值,第二个[Spinner2]有5个值。
现在,当用户从第一个下拉列表中选择值并从第二个下拉列表中选择另一个值时,a 片段显示在屏幕的一部分,带有webview文本。
这是我的代码
import android.R.string;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.AdapterView;
public class WebViewerFragment extends Fragment {
private WebView mWebView;
// a two dimensional array representing the data to put in the WebView
String SurgEqui="<html><body><h2>Equipment</h2><ul><li><p>IV catheter :Be certain that IV is in place and flushing easily</p></li></body><html>";
String[][] mData = new String[4][5];
/* String [][]mData={{Surg,Surg,Surg,Surg,Surg},{Surg,Surg,Surg,Surg,Surg}
{Surg,Surg,Surg,Surg,Surg}{Surg,Surg,Surg,Surg,Surg}{Surg,Surg,Surg,Surg,Surg}}
*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mainView = (View) inflater.inflate(R.layout.frag_layout, container, false);
mWebView = (WebView) mainView.findViewById(R.id.webView1);
return mainView;
}
public void updateWebView(int firstSelection, int secondSelection) {
if (firstSelection == AdapterView.INVALID_POSITION || secondSelection == AdapterView.INVALID_POSITION) {
return;
} else {
if (mWebView != null) {
mWebView.loadData(mData[firstSelection][secondSelection], "text/html", null);
}
}
}
}
现在有20个html字符串组合用于这两个下拉列表。如何使用此数组存储和检索值。如何将20个HTML字符串插入到数组中以便我可以使用 mWebView.loadData(mData [firstSelection] [secondSelection],“text / html”,null); 读取要在webview中显示的值的方法。
答案 0 :(得分:0)
使用2个阵列不是最好的吗?甚至只有一个包含20个条目的数组?如果您必须使用您的方法,那么您遇到了哪些问题?你评论的几乎是正确的:
String [][] mData= {
{Surg,
Surg,
Surg,
Surg,
Surg},
{Surg,
Surg,
Surg,
Surg,
Surg}, //<-- need comma between brackets
{Surg,
Surg,
Surg,
Surg,
Surg},
{Surg,
Surg,
Surg,
Surg,
Surg},
{Surg,
Surg,
Surg,
Surg,
Surg}
}; // <-- don't forget the semicolon