0
ArrayList<DataCCHeading>CC1=new ArrayList<DataCCHeading>();
ArrayList<DataCCHeading>CC2=new ArrayList<DataCCHeading>();

ArrayList<DataCCHeading>hd=new ArrayList<DataCCHeading>(result);
for (DataCCHeading dataCCHeading : hd) {
    if(dataCCHeading.Ownername==TAG_CC1HeadingData){
        CC1.add(dataCCHeading);
    }
    else if(dataCCHeading.Ownername==TAG_CC2HeadingData){
        CC2.add(dataCCHeading);
    }
}

ArrayAdapter<DataCCHeading>adaptercc1=new ArrayAdapter<DataCCHeading>(TimeClockDashBoard.this,android.R.layout.simple_spinner_item,CC1);
adaptercc1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
myCC1Spinner.setAdapter(adaptercc1);

ArrayAdapter<DataCCHeading>adaptercc2=new ArrayAdapter<DataCCHeading>(TimeClockDashBoard.this,android.R.layout.simple_spinner_item,CC2);
adaptercc2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
myCC2spinner.setAdapter(adaptercc2);

数据不显示... DataCCHeading 是类...

public class DataCCHeading {
    String Code;
    String Description;
    String Ownername;

    public DataCCHeading(String Code, String Description,String owner) {
        this.Code = Code;
        this.Description = Description;
        this.Ownername=owner;
    }

    public String toString() {
        return Description;
    }

    public String getId() {
        return Code;
    }

    public String GetDescription() {
        return Description;
    }

    public String Ownername()
    {
        return Ownername;
    }
}

我只想在微调器中显示描述。Spinner 不显示任何数据。请指导我。

4

2 回答 2

0

ArrayListCC1=新的 ArrayList();

ArrayListhd=新的 ArrayList(结果);

     for (DataCCHeading dataCCHeading : hd) {
         if(dataCCHeading.Ownername==TAG_CC1HeadingData)
         {
             CC1.add(dataCCHeading);

         }
    }

ArrayAdapteradaptercc1=新 ArrayAdapter(TimeClockDashBoard.this,android.R.layout.simple_spinner_item ,CC1); adaptercc1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); myCC1Spinner.setAdapter(adaptercc1);

于 2012-07-12T17:03:42.743 回答
0

这只是一个猜测,但在 Java 中你不能用来==比较字符串:

// This will not work! (Most of the time)
if(dataCCHeading.Ownername==TAG_CC1HeadingData)

必须使用 String.equals() 来比较完全匹配:

if(dataCCHeading.Ownername.equals(TAG_CC1HeadingData)){
    CC1.add(dataCCHeading);
}
else if(dataCCHeading.Ownername.equals(TAG_CC2HeadingData)){
    CC2.add(dataCCHeading);
}
else {
    Log.w("Warning!", "Data for Spinners does not match CC1 or CC2 HeadingData");
}
于 2012-07-10T23:23:19.990 回答