0

您好,我有 2 个下拉菜单。第一个下拉菜单 [Spin​​ner1] 有 4 个值,第二个 [Spin​​ner2] 有 5 个值。

现在,当用户从第一个下拉列表中选择值并从第二个下拉列表中选择另一个值时,会在屏幕的一部分中显示一个带有 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] , "文本/html", null); 读取要在 webview 中显示的值的方法。

4

1 回答 1

0

最好只使用2个数组吗?甚至只有 1 个包含 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
于 2012-12-01T04:01:11.227 回答