-2
您好我已經創建了先進的枚舉類的構造函數是這樣的:通行證枚舉對象數組適配器
public enum MyEnum{
MY_VAL1("par0", "par1"),
MY_VAL2("par0", "par1"),
MY_VAL3("par0", "par1");
private final String firstName;
private final String lastName;
MyEnum(String firstName, String lastName) {
this.firstName= firstName;
this.lastName= lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
}
接下來我creted我的新的適配器,並通過枚舉作爲將顯示在列表中的數據,但這種解決方案不起作用。你能告訴我爲什麼以及如何修復它?我會很樂意提供任何建議。
錯誤:MyEnum []在MyAdapter不能應用於
這是我adapater聲明:
MyEnum[] me = MyEnum.values();
ListAdapter myAdapter= new MyAdapter(this, me)
ListView list = (ListView) rootView.findViewById(R.id.myListView);
list.setAdapter(myAdapter);
感謝。
編輯:加入適配器代碼
公共類MyAdapter延伸ArrayAdapter {
MyAdapter (Context context, MyEnum[] enums) {
super(context, R.layout.custom_item, enums);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView = inflater.inflate(R.layout.custom_item, parent, false);
MyEnum item = (MyEnum) getItem(position);
TextView itemFirstName = (TextView) customView.findViewById(R.id.firstName);
TextView itemLastName = (TextView) customView.findViewById(R.id.lastName);
itemFirstName .setText(item.getFirstName());
itemLastName .setText(item.getLastName());
return customView;
}
}
發佈適配器代碼 –
您面臨的確切錯誤是什麼? –
「不起作用」不足以說明您的問題。 – khelwood