2016-11-09 43 views
0

我正在使用sax xml parsing並將數據存儲到模型類的array list帶模型類的數組列表在同一索引處存儲多個值

在此基礎上,我動態生成buttons

這裏是xml數據。

 <SalesLocation> 

      <SalesLocationGroup>0</SalesLocationGroup> 

     </SalesLocation> 
     <SalesLocation> 

      <SalesLocationGroup>0</SalesLocationGroup> 

     </SalesLocation> 
     <SalesLocation> 

      <SalesLocationGroup>1</SalesLocationGroup> 

     </SalesLocation> 
     <SalesLocation> 

      <SalesLocationGroup>2</SalesLocationGroup> 


     </SalesLocation> 
     <SalesLocation> 

      <SalesLocationGroup>3</SalesLocationGroup> 

     </SalesLocation> 
     <SalesLocation> 

      <SalesLocationGroup>4</SalesLocationGroup> 

     </SalesLocation> 

現在這裏用的Sales Location Group Value我添加按鈕Linear Layout的基礎上,上面的XML。

private ArrayList<ModelSalesLocation> arrayListSalesLocation; 

final Button tableButton = new Button(this); 
    tableButton.setId(iTable); 
    tableButton.setText(arrayListSalesLocation.get(iTable).getSalesLocationName()); 


final LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); 

    if (arrayListSalesLocation.get(iTable).getSalesLocationGroup().equals("0")) { 
     int wd = ((Integer.parseInt(arrayListSalesLocation.get(iTable).getTableWidth()) * deviceWidth)/1080); 
     Log.w("Final Width", "" + wd); 
     linearParams.width = wd; 

     int ht = ((Integer.parseInt(arrayListSalesLocation.get(iTable).getTableHeight()) * deviceHeight)/1776); 
     Log.w("Final Height", "" + ht); 
     linearParams.height = ht; 

     int top = ((Integer.parseInt(arrayListSalesLocation.get(iTable).getTopLocation()) * deviceHeight)/1776); 
     Log.w("Final Top", "" + top); 
     linearParams.topMargin = top; 

     int left = ((Integer.parseInt(arrayListSalesLocation.get(iTable).getLeftLocation()) * deviceWidth)/1080); 
     Log.w("Final Left", "" + left); 
     linearParams.leftMargin = left; 

     linearTableMain.addView(tableButton, linearParams); 
} 

現在,這裏如果Sales Location Group包含0多次,所以對別人的話,我需要把它添加到數組列表上相同的索引。

目前我在不同的指數上得到兩個值。

如何在相同索引處添加多個值並在此基礎上顯示按鈕。

讓我知道你是否需要這方面的更多信息。

在此先感謝。

回答

0

有一個哈希表像HashMap<integer,List<String>>
sampleList.add(index1data);sampleList.add(index2data);

sampleMap.put(0,sampleList)

+0

我知道有'HashMap'但我們可以使用模型類的'ArrayList'目前的情況怎麼辦? –

+0

你能告訴我更多的代碼嗎? –

相關問題