带有模型类的数组列表在同一索引处存储多个值

时间:2021-12-15 15:41:29

I am working with sax xml parsing and storing data to array list with model class.

我正在使用sax xml解析并将数据存储到带有模型类的数组列表中。

On the basis of that i am generating buttons dynamically.

在此基础上我动态生成按钮。

Here is the xml data.

这是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>

Now here with above xml on the basis of Sales Location Group Value i am adding buttons to 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);
}

Now here if Sales Location Group contains 0 multiple times and so on others then i need to add it to array list on same index.

现在,如果销售位置组包含多次0等等,那么我需要将它添加到同一索引上的数组列表中。

Currently i am getting both values on different index.

目前我在不同的索引上得到两个值。

How to add that multiple values at same index and show buttons on basis of that.

如何在同一索引处添加多个值并在此基础上显示按钮。

Let me know if you need more information in this regards.

如果您在这方面需要更多信息,请与我们联系。

Thanks in advance.

提前致谢。

1 个解决方案

#1


0  

have a hash map like HashMap<integer,List<String>>
eg sampleList.add(index1data);sampleList.add(index2data);

有一个哈希映射,如HashMap >,例如sampleList.add(index1data); sampleList.add(index2data); ,list>

sampleMap.put(0,sampleList)

#1


0  

have a hash map like HashMap<integer,List<String>>
eg sampleList.add(index1data);sampleList.add(index2data);

有一个哈希映射,如HashMap >,例如sampleList.add(index1data); sampleList.add(index2data); ,list>

sampleMap.put(0,sampleList)