Android ListView with fast scroll and alphabetical section index

后端 未结 3 1485
感情败类
感情败类 2020-12-05 19:49

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 e

相关标签:
3条回答
  • 2020-12-05 20:26

    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

    0 讨论(0)
  • 2020-12-05 20:32

    Hear is one cool example of what you need https://github.com/woozzu/IndexableListView

    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 < value.length() && j < keyword.length());
    
            return (j == keyword.length())? true : false;
        }
    
        private static boolean isKorean(int i) {
            return false;
        }
    
        private static boolean isInitialSound(int i) {
            return false;
        }
    }
    
    0 讨论(0)
  • 2020-12-05 20:41

    I have displayed the list inside a fragment, if you want to display in main activity then you can pass this, instead of getActivity()

    //method to display the side indexed scroll list of alphabets 
        public void displayAlphabetsList() {
            final List<String> listOfAlphabet = new ArrayList<>();
            for (int i = 0; i < 26; i++) {
                char alphabet = (char) (ASCII_VALUE_OF_A + i);
                listOfAlphabet.add(String.valueOf(alphabet));
            }
    
            ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, listOfAlphabet);
           alphabets_List_View.setAdapter(adapter);
    
            alphabets_List_View.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    ///scroll the recycler view to that position where matching letter was found
                    int positionToScroll = 0;
                    for (int i = 0; i < mContacts.size(); i++) {
                        if (mContacts.get(i).getFirstName().startsWith(listOfAlphabet.get(position)))
                            break;
                        else
                            positionToScroll++;
                    }
                    recyclerView.scrollToPosition(positionToScroll);
                }
            });
        }
    
    0 讨论(0)
提交回复
热议问题