Android ListView with fast scroll and alphabetical section index
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
How to add testview when touching a letter on right alphabet panel as shown in images? Could you please help me? Below is my code.
In details, I am looking for an example exactly like below image. Currently I did the sorting of data. When I click on right alphabet panel it shows the data properly. But the problem is when touching a letter the right alphabet panel I need to show what letter he is pressing in large size shown in image(E). How can I do it, could you please help me? Thank you in advance!
// MainActivity.java public class MainActivity extends Activity implements SearchView.OnQueryTextListener, SearchView.OnCloseListener { private IndexableListView listView; private SearchView search; EfficientAdapter objectAdapter; EfficientAdapter2 objectAdapter1; int textlength = 0; private CheckBox checkStat, checkRoutine, checkTat; private ArrayList patientListArray; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.homempleb); Log.i("scan"," txtScanResult "); ActionItem nextItem = new ActionItem(); final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL); quickAction.addActionItem(nextItem); quickAction.setOnDismissListener(new QuickAction.OnDismissListener() { @Override public void onDismiss() { Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show(); } }); listView = (IndexableListView) findViewById(R.id.homelistView); listView.setTextFilterEnabled(true); listView.setFastScrollEnabled(true); listView.setFastScrollAlwaysVisible(true); objectAdapter = new EfficientAdapter(this); listView.setAdapter(objectAdapter); } @Override public boolean onClose() { return false; } @Override public boolean onQueryTextChange(String newText) { return false; } @Override public boolean onQueryTextSubmit(String query) { return false; } }
...
// EfficientAdapter.java public class EfficientAdapter extends BaseAdapter implements SectionIndexer { private String mSections = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ArrayList patientListArray; private LayoutInflater mInflater; private Context context; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); this.context=context; String patientListJson = CountriesList.jsonData; JSONObject jssson; try { jssson = new JSONObject(patientListJson); patientListJson = jssson.getString("PostPatientDetailResult"); } catch (JSONException e) { e.printStackTrace(); } Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray Jarray = parser.parse(patientListJson).getAsJsonArray(); patientListArray = new ArrayList(); for (JsonElement obj : Jarray) { Patient patientList = gson.fromJson(obj, Patient.class); patientListArray.add(patientList); Collections.sort(patientListArray, new Comparator
This is a library project I created, because I had to use this scrolling pattern in a few recent apps, so I thought others might be interested in it. It's fairly easy to use, see readme in the github link above.
IN order to compile the project and get rid of korean text update the StringMatcher class
package com.woozzu.android.util; public class StringMatcher { public static boolean match(String value, String keyword) { if (value == null || keyword == null) return false; if (keyword.length() > value.length()) return false; int i = 0, j = 0; do { int vi = value.charAt(i); int kj = keyword.charAt(j); if (isKorean(vi) && isInitialSound(kj)) { } else { if (vi == kj) { i++; j++; } else if (j > 0) break; else i++; } } while (i
If you want to show the alphabet clicked as a Toast (a custom toast like the one shown in the image) use this:
view.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_custom_layout, (ViewGroup) findViewById(R.id.toast_layout_root)); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.BOTTOM, 0, 0); // to position the Toast on the screen toast.setDuration(Toast.LENGTH_LONG); // to set the duration, the toast should appear toast.setView(layout); // a custom layout for the toast toast.show(); } });
and your toast_custom_layout.xml will be a 100 x 100 layout with large text size