List of usage examples for android.widget ArrayAdapter sort
public void sort(@NonNull Comparator<? super T> comparator)
From source file:com.urbantamil.projmadurai.TamilInfoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ArrayAdapter<String> adapter_tamil_strings; // Inflate the layout for this fragment final View tamilinfo = inflater.inflate(R.layout.fragment_tamil_info, container, false); final ListView lv_tamilinfo = (ListView) tamilinfo.findViewById(R.id.listview_tamil_info_sort); adapter_tamil_strings = new ArrayAdapter<String>(tamilinfo.getContext(), android.R.layout.simple_list_item_1, mAUTHOR); lv_tamilinfo.setAdapter(adapter_tamil_strings); // use toggle button to flip the genre/author info // then sort the data final Button btn_tamilinfo = (Button) tamilinfo.findViewById(R.id.button_tamil_info_sort); final ToggleButton toggle_btn = (ToggleButton) tamilinfo.findViewById(R.id.toggle_tamil_info_category); toggle_btn.setOnClickListener(new View.OnClickListener() { @Override/*from w w w . ja v a 2 s . c om*/ public void onClick(View v) { List<String> ref_array = toggle_btn.isChecked() ? mGENRE : mAUTHOR; lv_tamilinfo.setAdapter(new ArrayAdapter<String>(tamilinfo.getContext(), android.R.layout.simple_list_item_1, ref_array)); lv_tamilinfo.invalidate(); lv_tamilinfo.setTag(ref_array); } }); /// sorting activity btn_tamilinfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List<String> ref_array = toggle_btn.isChecked() ? mGENRE : mAUTHOR; ArrayAdapter<String> adapter_str = new ArrayAdapter<String>(lv_tamilinfo.getContext(), android.R.layout.simple_list_item_1, ref_array); adapter_str.sort(utf8.comparator); lv_tamilinfo.setAdapter(adapter_str); lv_tamilinfo.invalidate(); } }); return tamilinfo; }
From source file:com.theelix.libreexplorer.FileManagerActivity.java
/** This function reads the current Folder, and populates the ListView with the content of that folder */ public void refresh() { ((ViewGroup) findViewById(R.id.list_layout)).removeView(itemView); if (FileManager.getCurrentDirectory().getName().equals("")) { mActionBar.setTitle(getString(R.string.app_name)); } else {//w ww.jav a 2 s .com mActionBar.setTitle(getString(R.string.app_name) + ": " + FileManager.getCurrentDirectory().getName()); } boolean useGrid = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_layout_grid", false); int itemLayout; if (useGrid) { itemView = new GridView(this); itemLayout = R.layout.file_grid_element; ((GridView) itemView).setNumColumns(4); ((GridView) itemView).setHorizontalSpacing(0); } else { itemView = new ListView(this); itemLayout = R.layout.file_list_element; } boolean hideHiddenFiles = !PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("pref_show_hidden_files", false); try { ArrayList<File> fileList = new ArrayList<>( Arrays.asList(FileManager.getCurrentDirectory().listFiles())); for (int i = 0; i < fileList.size(); i++) { if (fileList.get(i).isHidden() && hideHiddenFiles) { fileList.remove(fileList.get(i)); } } ArrayAdapter<File> filelistAdapter = new FileListArrayAdapter(this, itemLayout, fileList); filelistAdapter.sort(new FileComparator()); itemView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); ActionModeCallback callback = new ActionModeCallback(); callback.setListView(itemView); callback.setContext(this); itemView.setMultiChoiceModeListener(callback); mDrawerLayout.closeDrawers(); itemView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { File file = (File) adapter.getItemAtPosition(position); if (file.isDirectory()) { FileManager.setCurrentDirectory(file); } else { FileManager.openFile(file); } } }); itemView.setAdapter(filelistAdapter); itemView.setTextFilterEnabled(true); ((ViewGroup) findViewById(R.id.list_layout)).addView(itemView, new AbsListView.LayoutParams( AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT)); } catch (NullPointerException e) { Toast.makeText(this, "Unable to Access File", Toast.LENGTH_LONG).show(); } //Check if SDCard is mounted, if so shows External Storage on the Sidebar if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Environment.getExternalStorageState(new File(System.getenv("SECONDARY_STORAGE"))) .equals(Environment.MEDIA_MOUNTED)) { findViewById(R.id.menu_external_storage).setVisibility(View.VISIBLE); } else { findViewById(R.id.menu_external_storage).setVisibility(View.GONE); } } else { //Dirty method, but I think is the only option for devices before L if (new File(System.getenv("SECONDARY_STORAGE")).canRead()) { findViewById(R.id.menu_external_storage).setVisibility(View.VISIBLE); } else { findViewById(R.id.menu_external_storage).setVisibility(View.GONE); } } }