带模型类的数组列表在同一索引处存储多个值
问题描述:
我正在使用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多次,所以对别人的话,我需要把它添加到数组列表上相同的索引。
目前我在不同的指数上得到两个值。
如何在相同索引处添加多个值并在此基础上显示按钮。
让我知道你是否需要这方面的更多信息。
在此先感谢。
答
有一个哈希表像HashMap<integer,List<String>>
如 sampleList.add(index1data);sampleList.add(index2data);
sampleMap.put(0,sampleList)
我知道有'HashMap'但我们可以使用模型类的'ArrayList'目前的情况怎么办? –
你能告诉我更多的代码吗? –