private void initialize() { LearnBartender lbartend = LearnBartender.getInstance(); TreeMap<String, String> hashtable = lbartend.lesson; Set<String> set = hashtable.keySet(); String[] titles = set.toArray(new String[set.size()]); searchbox = (EditText) findViewById(R.id.etSearch); searchbox.addTextChangedListener(this); if (isGlasses) setListAdapter(new ImageAndTextListAdapter(this, R.layout.item_row, titles)); else setListAdapter(new ArrayAdapter<String>(this, R.layout.textviewrow, titles)); getListView().setTextFilterEnabled(true); }
/* (non-Javadoc) * @see android.text.TextWatcher#onTextChanged(java.lang.CharSequence, int, int, int) */ public void onTextChanged(CharSequence s, int start, int before, int count) { Editable et = searchbox.getText(); String letters = et.toString().trim(); LearnBartender lbartend = LearnBartender.getInstance(); TreeMap<String, String> hashtable = lbartend.lesson; Set<String> set = hashtable.keySet(); String[] titles = set.toArray(new String[set.size()]); ArrayList<String> newTitles = new ArrayList<String>(); for (int i = 0; i < titles.length; i++) { String key = titles[i]; if (key.toLowerCase().startsWith(letters.toLowerCase())) newTitles.add(key); } titles = newTitles.toArray(new String[newTitles.size()]); if (isGlasses) setListAdapter(new ImageAndTextListAdapter(this, R.layout.item_row, titles)); else setListAdapter(new ArrayAdapter<String>(this, R.layout.textviewrow, titles)); getListView().setTextFilterEnabled(true); }