从其他类中获取列表的最大大小

时间:2013-03-13 12:43:35

标签: java for-loop size

我试图在另一个类上获取列表的最大大小,将其设置为循环到另一个类的最大大小。结果,它没有读取我得到的大小。这是代码:

Users.java

private void populateList() {
    CusInfoManipulator c = new CusInfoManipulator(this);
    int max = c.getMaxSize();
    for(int x = 0;x<max;x++){
        HashMap<String, String> value= new HashMap<String,String>();
        c.listData(x);
        value.put("username", "Username: " + c.getUserL());
        value.put("name","Customer Name: "+ c.getFnameL() +" "+ c.getLnameL());
        value.put("address", "Address: " + c.getAddressL());
        value.put("landmark", "Landmarks: " + c.getLandmrkL());
        value.put("num1", "Contact Number 1: " + c.getNumL());
        value.put("num2","Contact Number 2: " + c.getNum2L());
        list.add(value);
    }
}

解析云中列表的最大大小:

List<ParseObject> searchItems = query.find();
int max = searchItems.size();

public int getMaxSize() {
    return max;
}

有人可以帮我弄清楚我的代码出了什么问题以及为什么它没有达到最大尺寸?

2 个答案:

答案 0 :(得分:0)

不确定,但也许你应该这样做:

public int getMaxSize()
 {
    List<ParseObject> searchItems = query.find();
    int max = searchItems.size();
    return max;
 }

答案 1 :(得分:-1)

getMaxSize方法应该返回类似list.size()而不是常量值的内容