【问题标题】:array list with model class store multiple values at same index具有模型类的数组列表在同一索引处存储多个值
【发布时间】:2016-11-09 09:55:06
【问题描述】:

我正在使用 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 的基础上使用上面的xml 我正在向Linear Layout 添加按钮。

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 多次等等,那么我需要将它添加到同一索引上的数组列表中。

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

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

如果您需要这方面的更多信息,请告诉我。

提前致谢。

【问题讨论】:

    标签: android android-studio arraylist saxparser


    【解决方案1】:

    有一个像HashMap&lt;integer,List&lt;String&gt;&gt;这样的哈希映射
    例如 sampleList.add(index1data);sampleList.add(index2data);

    sampleMap.put(0,sampleList)

    【讨论】:

    • 我知道HashMap 但是我们可以使用模型类的ArrayList 来处理当前场景?
    猜你喜欢
    • 2015-09-16
    • 2020-08-20
    • 2021-12-11
    • 2018-08-28
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 2012-02-08
    相关资源
    最近更新 更多