Quick Scroll Bar in alphabetical order

Asked

Viewed 330 times

4

I’ve already found some examples with a custom view of a list with a alphabetical quick scroll bar, but I didn’t really find a scroll bar that really looks like the one from my Kitkat contact list.

I do not understand why this is not a native element, since it is used on any android since version 4.0.

I have an example using Sectionindexer to sort and split alphabetically - which I did at the time to be like iOS - but it’s old and very ugly:

I want a scrollbar like this:

Does anyone have an example or tip for me?

=========================================================================

UPDATE - RESOLVED

I found this example on the Android developers page, and on the right sidebar you can download the source of a perfect example!

Follows the link

  • Consider the possibility of designing the solution in the answer field, to help others with the same problem.

  • I didn’t know what was best, I’ll do it then

2 answers

0


I found this example on the Android Developers page, and in the right sidebar you can download the source of a perfect example!

Retrieving a List of Contacts

This Lesson shows you how to Retrieve a list of Contacts Whose data Matches all or part of a search string, using the following Techniques:

Match contact Names
Retrieve a list of Contacts by matching the search string to all or part of the contact name data. The Contacts Provider Allows Multiple instances of the same name, so this technique can Return a list of Matches.

Match a specific type of data, such as a phone number
Retrieve a list of Contacts by matching the search string to a particular type of Detail data such as an email address. For example, this technique Allows you to list all of the Contacts Whose email address Matches the search string.

Match any type of data
Retrieve a list of Contacts by matching the search string to any type of Detail data, including name, phone number, street address, email address, and so Forth. For example, this technique Allows you to Accept any type of data for a search string and then list the Contacts for which the data Matches the string.

Note: All the examples in this Lesson use a Cursorloader to Retrieve data from the Contacts Provider. A Cursorloader runs its query on a thread that’s Separate from the UI thread. This Ensures that the query doesn’t slow down UI Response times and cause a Poor user Experience. For more information, see the Android training class Loading Data in the Background.

0

XML inside a layout:

<ListView
    android:id="@+id/list_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fastScrollEnabled="true"
    android:fastScrollAlwaysVisible="true"
    android:cacheColorHint="@android:color/transparent" />

Activity you need a String List so if you have a complex list you should take the item you need as in the example:

public class Activity extends Activity {

ListView list_view;

private List<MeuItem> items;
private List<String> nomes;
private SimpleAdapter indexAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    setContentView(R.layout.myview);
    items = new ArrayList<MeuItem>();
    nomes = new ArrayList<String>();

    for (Item i : items) {
        nomes.add(i.getNomeQueEuQueroQueApareca());
    }

    Collections.sort(nomes);
    adapter = new SimpleAdapter(this, nomes);
    list_view.setAdapter(adapter);  

  }
}
  • This is a simple list, I want one with alphabetical division as the contact list, but I already got an example. Then put here

  • Too bad you didn’t test the code it took me a few minutes to rewrite. What you want is native and what makes it work are the lines: android:fastScrollEnabled="true" android:fastScrollAlwaysVisible="true" Test and you won’t need any library.

  • In vdd I know these attributes, were even the ones I used in the first example, but by far this solves what I need. I have to use sectionIndexer and Alphabetindexer. But thanks anyway

Browser other questions tagged

You are not signed in. Login or sign up in order to post.