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中只显示描述。 Spinner不显示任何数据。请指导我。
答案 0 :(得分: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");
}
答案 1 :(得分:0)
ArrayListCC1 = new ArrayList();
ArrayListhd = new ArrayList(result);
for (DataCCHeading dataCCHeading : hd) {
if(dataCCHeading.Ownername==TAG_CC1HeadingData)
{
CC1.add(dataCCHeading);
}
}
ArrayAdapteradaptercc1 = new ArrayAdapter(TimeClockDashBoard.this,android.R.layout.simple_spinner_item ,CC1); adaptercc1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); myCC1Spinner.setAdapter(adaptercc1);