Headings under Navigation Drawer - android

How to add Headings in drawer layout. For example in YouTube application it has Headings in it's drawer like Subscription and from YouTube... So How we can add such Headings in Drawer Layout?
Check below image I want to add heading like "Subscription" used in this image.

The magic is happening in the Adapter that is feeding views to the ListView.
When a ListView is scrolled, it has to display whatever row is next in the data set. Instead of having to do this on their own, ListViews are backed by an Adapter. The ListView essentially asks the adapter for the next view (naming an index value) every time it needs to scroll up or down.
The Adapter can pass the ListView whatever it wants. When the ListView asks for row x (an index value), the Adapter can look at the data set and see that row x should be a special header. The adapter builds or recycles a special header view and passes it to the list view.
See the List View Guide for example code.

Related

Inner List in Android

I have a problem with lists.
I want to implement a scrollable big list, each element of which contains a text on the left side and a NON-scrollable inner list on the right side. (for example: the name of the flat and the list of its inhabitants names)
Both lists should be filled from the cursors and contain an informatio about them: I want to have an oppurtunitz to get all cursos fields when I click an element of the inner list.
As far as I understood I's not possible to solve it with two ListViews. ExpandableListView does not pass me because I do not want to expand the first list, I want to have the inner list always visible.
Do you have any ideas how can I realize it?
Try using a ListView for your big list, and an empty LinearLayout in each item. You fill the LinearLayout of each item programmatically in the big list adapters getView(..) method, where int position is the item number.
See also: android nested listview
Edit: Or use an ExpandableListView, which items you expand programmatically without animation with expandGroup(int position, boolean animate). Prevent collapsing by setting an ExpandableListView.OnGroupCollapseListener, in which you expand the group again. (seems a bit hacky)
Dokumentation: https://developer.android.com/reference/android/widget/ExpandableListView.html

Android listview row detail page sliding

I have ListView which has many items(rows), onClick of any item goes to the DetailActivity which explains more about that particular item. If I want to see the detail of the next item, I have to come back to the ListView and click next item. How to design to see the next or previous item's detail from DetailActivity by swiping it left or right.
I assume that you have a Custom Object and ArrayList of this object.
You need to have an adapter to Show this Arraylist into Listview
When you clicked the list item you need to pass your object from ListActivity to your DetailActivity
I think you are doing this fine until this part.
Then now, you can use ViewPager and its adapter in your DetailActivity.
When you click the list item, you need to pass your Arraylist and your object index to the DetailActivity.
In the DetailActivity, get your Arraylist, set your List into ViewPager adapter, find your object via index(that you clicked) and set ViewPager page index as your wanted item index.
If you manage this correctly, you can slide details of your content. You can ask ma anything to make this clear.
There is a tutorial of Using the ViewPager: http://architects.dzone.com/articles/android-tutorial-using
You could go with a ExpandableListView. No need to open a new screen or doing something which becomes hard to manage like Fragments. The user can show/hide detail just by clicking on the item.
A view that shows items in a vertically scrolling two-level list. This
differs from the ListView by allowing two levels: groups which can
individually be expanded to show its children. The items come from the
ExpandableListAdapter associated with this view.

Android- ListView items with dynamic content

I am having one problem with ListView.
I am generating a list view with dynamic TextViews(white boxes in image) in each item.
The ListView is populated using ArrayAdapter of 'Model' class. Some items can have 2 white boxes, some can have more which depends upon the data/count from 'Model'. Also, I am using ViewHolder pattern and can maintain other states of the list item. But these boxes are added dynamically in getView() method.
So my question is, how to maintain state of these dynamically added TextViews using ViewHolder or any other method when ListView is scrolled.
I guess the no.of boxes changes on scroll, but you need the dynamic no.of boxes to be alloted in a list items?
Solution:
Set the size (i.e) no.of boxes in a list item to an integer array. (like: size[position] = 5).
The size should be set, before the list adapter or base adapter loads the list items.
Now at the end of getView() of base adapter, right the code given below
for(int i = 0; i< size[position]; i++){
//generate textview i.e white boxes here
}
I had the same problem in dynamic list, this solved the issue.
If still you have problem kindly post your the code here.
You need to have a list or some data structure in which to store the content of the data you put in from the ui, for instance a SparseArray<ModelUI>. Your ModelUI class should have some string properties to store the text from your dynamic textboxes.
Also, you need to take into account that you're handling two indexes here: one index/key in the SparseArray which is the real index in your list of Model objects and an index of the items visible in your Listview.
Let's say you have a list of 100 items, in your listview you'll always display 10; you'll always have to refer to the firstVisibleIndex from your listView.
If I understand correctly, you'd like to edit a textbox, scroll 50 items, scroll back to the edited item and see the correct text in the textbox, right?

ListView items outside initial view aren't clickable

I have four ListViews which I synchronize their scrolling in order to scroll simultaneously when either of them is scrolled. The first ListView is filled by a custom adapter and contains only a TextView and the rest three are filled by another custom adapter and contain a RatingBar. Both adapters extend ArrayAdapter.
Here's the problem:
Whenever I scroll one of them, although the scrolling process is smooth and in sync, the items outside the initial View don't behave properly.
I cannot click on them. I get a null pointer exception.
They get the data located in the initial View.
green get same data
red are not interactive
I believe that it has something to do with the getView() when I scroll. The fields don't get populated correctly. Isn't getView() supposed to be called when a ListView is scrolled?

Android listview with horizontal lines when empty

I have a Listview in my Android app, and I want there to be some horizontal lines when the list is empty to indicate to the user that this is a List. I know that there is the setEmptyView method on ListView, but I'm not sure what to put in that view if I want there to be list rows with horizontal lines. How would I accomplish this?
Having a bunch of horizontal lines for an empty list is an iOS convention. If you want your app to fit in with Android better you should set something else. Perhaps notify the user there was an error or that there are no items in the list. You can add this right to your layout.xml file if you're using a ListActivity. All you need to do is create a view and give it the id #android:id/empty.
put the listView in a FrameLayout and add another view in that Frame.
if you having any item in the list hide its (visiblity="gone") and show the other view.
OR
change your adapter to return multi ViewType
in your adapter if you have no item return other type of view

Categories

Resources