3

ArrayAdapter<Summary>イベントのリストを保持するカスタムがあります。に重複した値があるため、 toList<Summary>の値を入力しようとしていますが、空白のページが表示されます。List<Summary>LinkedHashSet<Summary>

ArrayListカスタムを変換しLinkedHashSetて一意のデータを取得するにはどうすればよいですか?

Main.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) ...
4

1 に答える 1