Reputation: 4570
I'm working on a sort of contacts book for my app, I want to do something like in the picture beneath:
The contact names will be in a scrollable list, but I want the letetr on the left to follow the names until the next letter shows up. I'm not quite sure how to do this, I thought of having a structure like this in the corresponding xml layout file:
<LinearLayout>
<ListView>
<ImageView />
<ListView />
</ListView>
</LinearLayout>
Is this the right way to go about it ?
Upvotes: 2
Views: 447
Reputation: 17429
If you want to implement it with a RecyclerView
you can take a look at this project. You can customize the left pin either with a simple text or an image.
The idea is to use a CoordinatorLayout
in which you have the pin. Assigning a behavior to this pin you can get the result you want.
Upvotes: 0
Reputation: 75788
@Husayn Hakeem : For your information,Your requiremet is Lollipop's Contacts. Its special type of ListView (PinnedHeaderListView)with pinned section headers for Android.So please check ListViewVariants Demo .I hope it helps you.
Upvotes: 2
Reputation: 4656
What you have to do is to add an OnScrollListener
(listView.setOnScrollListener
) to your listview. Then implements the methods
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
and/or
public void onScrollStateChanged(AbsListView view, int scrollState)
With the first one, you have a lot of information to use to manage what you want. For example, if you want the letter to correspond to the first element in the list view, You get the first letter of the first element and draw it
.
Upvotes: 1