private ArrayAdapter<String> getArrayAdapter(String[] arr) { ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arr); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.sort(comparator); return adapter; }
protected void sort() { super.sort( new Comparator<T>() { @Override public int compare(T lhs, T rhs) { return lhs.compareTo(rhs); } }); }
private void spinnerSort() { spinnerAdapter.sort( new Comparator<TaskGroup>() { @Override public int compare(TaskGroup a, TaskGroup b) { return a.getName().toString().compareTo(b.getName().toString()); } }); }
private void updateKeyListAdapter() { mKeyListAdapter.clear(); for (long keyCombo : mKeyCombos) { mKeyListAdapter.add(describeExtendedKeyCode(keyCombo)); } /* Sort the list so the keys appear in a consistent place */ mKeyListAdapter.sort( new Comparator<CharSequence>() { @Override public int compare(CharSequence charSequence0, CharSequence charSequence1) { return String.CASE_INSENSITIVE_ORDER.compare( charSequence0.toString(), charSequence1.toString()); } }); }
public void notifyFileImported(File file) { if (adapter.getPosition(file) == -1) { adapter.add(file); adapter.sort( new Comparator<File>() { @Override public int compare(File lhs, File rhs) { return lhs.compareTo(rhs); } }); } adapter.notifyDataSetChanged(); }
public void updateListView() { final EditText searchBar = (EditText) findViewById(R.id.searchEditText); final File dir; if (scoutOrSuperFiles) { dir = new File( android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/Super_scout_data"); } else { dir = new File( android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/Scout_data"); } if (!dir.mkdir()) { Log.i("File Info", "Failed to make Directory. Unimportant"); } final File[] files = dir.listFiles(); adapter.clear(); for (File tmpFile : files) { adapter.add(tmpFile.getName()); } searchBar.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { if (searchBar.getText().toString().equals("")) { adapter.clear(); searchBar.setFocusable(false); for (File tmpFile : files) { adapter.add(tmpFile.getName()); } searchBar.setFocusableInTouchMode(true); adapter.sort( new Comparator<String>() { @Override public int compare(String lhs, String rhs) { File lhsFile = new File(dir, lhs); File rhsFile = new File(dir, rhs); Date lhsDate = new Date(lhsFile.lastModified()); Date rhsDate = new Date(rhsFile.lastModified()); return rhsDate.compareTo(lhsDate); } }); } else { for (int i = 0; i < adapter.getCount(); ) { if (adapter.getItem(i).startsWith((searchBar.getText().toString()).toUpperCase()) || adapter .getItem(i) .contains((searchBar.getText().toString()).toUpperCase())) { i++; } else { adapter.remove(adapter.getItem(i)); } } } } }); adapter.sort( new Comparator<String>() { @Override public int compare(String lhs, String rhs) { File lhsFile = new File(dir, lhs); File rhsFile = new File(dir, rhs); Date lhsDate = new Date(lhsFile.lastModified()); Date rhsDate = new Date(rhsFile.lastModified()); return rhsDate.compareTo(lhsDate); } }); adapter.notifyDataSetChanged(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mApp = (BTLedSignApp) getApplication(); setContentView(R.layout.btledsign_main); mViewBanner = (LedSignView) findViewById(R.id.ViewBanner); mViewBanner.setDisplay(mApp.getDisplay()); // Intent i = new Intent(this, TMAPLinkage.class); // startService(i); SeekBar speedBar = (SeekBar) findViewById(R.id.seekBarSpeed); if (speedBar != null) { speedBar.setOnSeekBarChangeListener( new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { if (mBoolPlay) { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { getWindow() .getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); } } } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { mIntPlaySpeed = progress; mViewBanner.setPlaySpeed(mIntPlaySpeed); Log.d(TAG, "H3 " + mIntPlaySpeed); if (mBTConnected) { byte[] bufSpeed = new byte[1]; bufSpeed[0] = (byte) (9 - mIntPlaySpeed); String str = String.format("VAL : %d", bufSpeed[0]); Log.d(TAG, str); // mApp.sendData(BTLedSignApp.IOCTL_LED_PLAY, bufSpeed, 20); } } }); speedBar.setProgress(0); } // Font List mHashFonts = FontManager.enumerateFonts(); if (mHashFonts != null) { Iterator<String> s = mHashFonts.keySet().iterator(); mSpinnerFont = (Spinner) findViewById(R.id.SpinnerFont); if (mSpinnerFont != null) { // mFontSelIdx = mFontSpinner.getSelectedItemPosition(); mArrayAdapterFont = new ArrayAdapter<String>(this, R.layout.font_list); if (mArrayAdapterFont != null) { mSpinnerFont.setAdapter(mArrayAdapterFont); String strFontFile; while (s.hasNext()) { strFontFile = s.next(); // Log.d("TEST", ">>>" + strFontFile + " : " + mFontList.get(strFontFile)); mArrayAdapterFont.add(strFontFile); } mArrayAdapterFont.sort(null); mSpinnerFont.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected( AdapterView<?> parent, View view, int position, long id) { if (mFontSelIdx != position) { String strFontName; strFontName = (String) mSpinnerFont.getItemAtPosition(position); mFontSelIdx = position; LogUtil.d("SEL %s : %s", strFontName, mApp.getDisplay().getText()); mApp.getDisplay().setFontName(strFontName); mViewBanner.invalidate(); } } public void onNothingSelected(AdapterView<?> parent) {} }); } } } }
public void sort() { super.sort(this); }