所以我有一个类似于...的枚举
package com.example.manageyobudget.model;
public enum FilingStatus {
//TODO: Would changing these texts to static or values help?
MARRIED("2:married", "Married"),
SINGLE("1:single", "Single"),
HEAD_OF_HOUSEHOLD("3:Head of Household", "Head of Household"),
SUPPLEMENTAL("4:Supplemental","Supplemental");
private String val;
private String text;
private FilingStatus(String val, String text){
this.val = val;
this.text = text;
}
public String getVal(){
return this.val;
}
public String getText(){
return this.text;
}
public static String[] getTexts(){
int count = FilingStatus.values().length;
String[] values = new String[count];
for(FilingStatus e : FilingStatus.values()){
values[count--]=e.text;
}
return values;
}
}
现在我想制作一个微调器,我希望 ArrayAdapter 成为枚举,而我希望显示文本是来自 text 属性的值。另一方面,我翻译了侦听器中的值,因此我假设我需要类似于...
Spinner filestat = (Spinner)rootView.findViewById(R.id.filestat);
filestat.setAdapter(new ArrayAdapter<FilingStatus>(this.getActivity(),
android.R.layout.simple_list_item_1,
FilingStatus.values()));
filestat.setOnItemSelectedListener(this);
但这将使用序号作为微调器中显示的值。我怎样才能使它成为文本属性?我是否需要创建一种基于文本查找枚举的方法?这似乎是很多开销。