0

I'm trying to make a spinner with an array that I retrieve from a database, here goes the code I'm trying to use:

    Unit unit;
    int idx = 1;
    ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(this,
            android.R.layout.simple_spinner_item, new Unit[] {   
                unit = connector.getUnit(idx);
                while (connector.getUnit(idx) != null){  
                new Unit(unit.getunitID(), unit.getunitTypeID(), unit.getorganizationID(), unit.getunitName(), unit.getunitAddress());
                unit = connector.getUnit(idx);
                idx++;
                }
                  });

connector.getUnit(idx) basically retrieves a Unit object from the database, will return a null value if there are not more units to retrieve. The compiler is complaining in:

unit = connector.getUnit(idx);

as "Syntax error, insert ")" to complete VariableInitializer"

and:

idx++;

as "Syntax error, insert "}" to complete Block"

I think that would be the right code to do what I want to, but somehow I can't manage to make it work, any idea?

Thanks in advance

4

1 回答 1

1

您尝试创建一组 Unit 对象。在 new Unit[] { } 的 "{" 和 "}" 之间,您只能使用用 "," 分隔的 Unit 对象。你有很多不符合这种语法的逻辑。您应该将其全部移到该初始化程序部分之外,并将已创建的 Unit 对象数组提供给 ArrayAdapter 构造函数。

于 2012-04-30T20:25:24.033 回答