2016-12-27 37 views
1
{ 
    "godowns": [ 
    { 
     "name": "godown1", 
     "code": "g001", 
     "item": [ 
     { 
      "name": "item1", 
      "code": "i001", 
      "qty": "20" 
     }, 
     { 
      "name": "item2", 
      "code": "i002", 
      "qty": "20" 
     } 
     ] 
    }, 
    { 
     "name": "godown2", 
     "code": "g002", 
     "item": [ 
     { 
      "name": "item1", 
      "code": "i006", 
      "qty": "20" 
     }, 
     { 
      "name": "item2", 
      "code": "i007", 
      "qty": "20" 
     } 
     ] 
    } 
] 
} 

我必須使用上面的json設置我的兩個微調值。第一個微調值是倉庫名稱,另一個微調值是項目名稱。如果我自動選擇第一個微調倉位名稱,第二個微調值必須根據倉位名稱進行更改......我的第一個微調值是godown1和godown2。我已經將這些值設置爲第一個微調器..但是我的問題是,如果我選擇了godown1,那麼我的另一個微調器僅從項目數組(如項目1,項目2)中進行賦值,而不是像項目1,項目2,項目1,項目2那樣的所有項目。 ..i獲得了項目數組中的所有項目......任何人都可以解釋並解決我的問題。當我在android中選擇微調項目時,如何獲得特定的數組項目?

+0

檢查此鏈接 SaTech

+0

用物品列表創建貨倉名稱的映射 - Map > godownItems;然後onItemSelected第一個微調控制器的偵聽器 - 從地圖上的對應於選定的黃昏的項目列表中獲取並將其設置爲第二個微調控制器。 – Arjit

+0

感謝您的回覆..我會嘗試 –

回答

0

創建地圖貨倉名與項目的列表 -

Map<String, List<String>> godownItems = new HashMap<>(); 

List<String> godown1Items = new ArrayList<>(); 
godownItems.put("godown1", godown1Items); 
godownItems.put("godown2", godown2Items); 


spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
    public void onItemSelected(AdapterView<?> parent, View view, 
       int pos, long id) { 
      //steps to follow 
      //1. get the selected godown name 
      //2. get the list of items using the godown name from the map 
      //3. set the list to the second spinner 
     } 

     public void onNothingSelected(AdapterView<?> parent) { 
      // Do nothing, just another required interface callback 
     } 

}); 
相關問題