@Override public void drop(int from, int to) { String item = adapter.getItem(from); adapter.remove(item); adapter.insert(item, to); adapter.notifyDataSetChanged(); Preferences prefs = new Preferences(getActivity()); reportClasses.add(to, reportClasses.remove(from)); prefs.setReportOrder(reportClasses); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); DragSortListView lv = (DragSortListView) getListView(); lv.setDropListener(new ReportDropListener()); adapter = new ArrayAdapter<>(getActivity(), R.layout.list_item_drag, android.R.id.text1); Preferences prefs = new Preferences(getActivity()); reportClasses = prefs.getReportOrder(); for (Class<? extends AbstractReport> reportClass : reportClasses) { AbstractReport report = AbstractReport.newInstance(reportClass, getActivity()); adapter.add(report.getTitle()); } setListAdapter(adapter); }