我有一个ArrayAdapter<Summary>
包含事件列表的自定义。中有重复的值List<Summary>
,所以我试图将值放入,List<Summary>
但这LinkedHashSet<Summary>
会显示一个空白页。
如何将自定义转换ArrayList
为LinkedHashSet
获取唯一数据?
主.java:
LinkedHashSet<Summary> listToSet = new LinkedHashSet<Summary>();
final List<Summary> summaries = new ArrayList<Summary>();
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.events_summary, container, false);
.......
setListView(month, year, date_value);
summaryAdapter = new SummaryAdapter(this.getActivity().getApplicationContext(), R.layout.listview_item_row, listToSet);
calendarSummary = (ListView) v.findViewById(R.id.calendarSummary);
calendarSummary.setAdapter(summaryAdapter);
return v;
}
public void setListView(int month, int year, int dv) {
events = new HolidayEvents();
_calendar = Calendar.getInstance(Locale.getDefault());
int totalDays = _calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
for(int i = 1; i <= totalDays; i++){
if(isHoliday(i, month, year, dv))
{
date = i + " " + getMonthForInt(month-1) + " " + year;
for (Event event : events.eventDetails(this, month, i))
{
summaries.add(new Summary(date, event.eventdetails));
listToSet.addAll(summaries);
}
}
}
}
ArrayAdapter.java:
public class SummaryAdapter extends ArrayAdapter<Summary>{
Context context;
int layoutResourceId;
LayoutInflater mInflater;
LinkedHashSet<Summary> list = null;
List<Summary> data = null;
public SummaryAdapter(Context context, int layoutResourceId, LinkedHashSet<Summary> summaries) {
super(context, layoutResourceId);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.list = summaries;
data = new ArrayList<Summary>(list); //converting LinkedHashSet to List
mInflater = LayoutInflater.from(context);
}
....rest of the code retrieving data by using data.get(position) ...