[英]Java Multi Dimension array -how to read values from spinners
Hello i have 2 drop downs .First drop down[Spinner1] has 4 values , second[Spinner2]has 5 values. 您好,我有2个下拉菜单。第一个下拉[Spinner1]有4个值,第二个[Spinner2]有5个值。
Now when user selects values from first drop down and another value from second drop down , a fragment shows up in a part of screen with a webview text. 现在,当用户从第一个下拉菜单中选择值,然后从第二个下拉菜单中选择另一个值时,屏幕上将显示一个带有Webview文本的片段。
This is my code 这是我的代码
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);
}
}
}
}
Now there are 20 html string combinations for these 2 drop downs.How can i use this array for storing and retrieving values.How can i insert 20 HTML strings into array so that i can use mWebView.loadData(mData[firstSelection][secondSelection], "text/html", null); 现在这20个下拉列表有20个html字符串组合。如何使用此数组存储和检索值。如何将20个HTML字符串插入数组,以便可以使用mWebView.loadData(mData [firstSelection] [secondSelection] ,“ text / html”,null); method to read values to display in webview. 读取要在webview中显示的值的方法。
wouldn't it be best to just use 2 arrays? 最好只使用2个数组? or even just 1 array with 20 entries? 甚至只有1个数组和20个条目? If you must use your method, what issues are you running into exactly? 如果必须使用您的方法,那么您到底遇到了什么问题? what you commented out is almost correct: 您评论的内容几乎是正确的:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.