android listview适配器组合了两个数组

时间:2015-03-07 10:45:33

标签: java android sqlite arraylist baseadapter

我有一些名单sqllite.i有一些表格,我选择姓名,例如来自AnotherTable的客户表和价格。我收到了两个数组列表。第一个名字的数组列表和第二个价格的数组列表。 这是我的来源

private ArrayList<GetDictioanyClassByPosition> GetPKFromTable() {
    price_array.clear();
    ArrayList<GetDictioanyClassByPosition> my_list = d_Helper
            .getAllPriceByPosition(0);
    for (int i = 0; i < my_list.size(); i++) {
        String AllPrice = my_list.get(i).getDictionaryPrice();
        GetDictioanyClassByPosition cnt = new GetDictioanyClassByPosition();
        System.err.println(AllPrice + "AllPrice");
        cnt.setDictionaryPrice(AllPrice);
        price_array.add(cnt);
    }
    return price_array;
}

这是检查价格数组列表的方法,此方法检查名称的数组列表

public void AllInfoFromLoanAnalysis() {

    name_list.clear();

    ArrayList<GetAllDictionariesClass> contact_array_from_db = d_Helper
            .getAllInformationFromLoanAnalysis_Table(1, 1);

    Log.e("Sizee", contact_array_from_db.size() + "sizee");
    for (int i = 0; i < contact_array_from_db.size(); i++) {
        int DictionaryID = contact_array_from_db.get(i).getDictionaryID();

        System.out.println(DictionaryID + "DictionaryID");

        GetDictioanyClassByPosition object = new GetDictioanyClassByPosition();
        String name = null ;

        ArrayList<GetDictioanyClassByPosition> DictionaryIdList = d_Helper
                .GetDictionaryIdList(DictionaryID);

        System.out.println(DictionaryIdList.size() + "DictionaryIdList");
        Log.e("Sizee2", DictionaryIdList.size() + "sizee2");

        for (int j = 0; j < DictionaryIdList.size(); j++) {
            name= DictionaryIdList.get(j).getDictionaryName();


            Log.e("object", name + "object");
            object.setDictionaryName(name);


            name_list.add(object);
        }

        for (int j = 0; j < price_array.size(); j++) {

            String AllPrice = price_array.get(i).getDictionaryPrice();
            object.setDictionaryPrice(AllPrice);
            object.setDictionaryName(name);
            price_array.add(object);
        }
        agroproductslistview.setAdapter(agroproduct_adapter);

    }
}

我打电话给我的BaseAdapter就像这样

_adapter = new LoanProductAdapter(
            getApplicationContext(), R.layout.productlistadapter,
            name_list);





public class GetDictioanyClassByPosition {
private String  DictionaryName;
private String DictionaryPrice;


public String getDictionaryName() {
    return DictionaryName;
}

public void setDictionaryName(String DictionaryName) {
    this.DictionaryName = DictionaryName;
}



public String getDictionaryPrice() {
    return DictionaryPrice;
}

public void setDictionaryPrice(String DictionaryPrice) {
    this.DictionaryPrice = DictionaryPrice;
}

}

我可以选择并在不同的数组列表中显示我的价格和名称,但我想要列出两个数组列表并在我的列表视图中适配 .how我可以解决我的问题吗? 如果有人知道解决方案,请帮助我 感谢

1 个答案:

答案 0 :(得分:0)

请参阅以下示例。

public ArrayList<customObject> _historyArrayList = new ArrayList<customObject>();
    public ArrayList<customObject> _completedArraylist = new ArrayList<customObject>();

合并只需使用:

 _historyArrayList.addAll(_completedArraylist);

注意:确保您的customObject相同