2012-11-30 33 views
0

你好,我有2個下拉。第一個下拉[Spin​​ner1]有4個值,第二個[Spin​​ner2]有5個值。Java多維數組 - 如何從旋轉器讀取值

現在,當用戶從第一個下拉菜單中選擇值並從第二個下拉菜單中選擇另一個值時, 片段顯示在屏幕的一部分中,並帶有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個這些2滴downs.How我可以使用此陣列,用於存儲和檢索的HTML字符串的組合values.How我可以插入件20個的HTML字符串到數組所以我可以使用 mWebView.loadData(mData [firstSelection] [secondSelection],「text/html」,null); 讀取要在webview中顯示的值的方法。

回答

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