How to implement sectioned listview like in youtube app Android - android

Does someone know to implement this kind of views structure in Android ? It's from youtube app.
Thanks for your help.

Android have a great little tool when you want to know how something was done.
It's the DDMS (device monitor), look around on Eclipse or Android Studio that you can find it.
Over there, you will find the option: "Dump View hierarchy for UIAutomator" and you can use it to get the View hierarchy of different apps. So for example YouTube:
You can see that it's just a normal ListView with a very cleverly built Adapter. Check out carefully the BaseAdapter class https://developer.android.com/reference/android/widget/BaseAdapter.html
specially two methods:
int getViewTypeCount();
int getItemViewType(int position);
those can be used to have different types of view depending on the position of the ListView. So then it's just built one-by-one, the types you want to implement.
The "more" will do nothing more than add more items the data backing the adapter and call notifyDataSetChanged()
happy coding...

You would need to create more than 1 listview and use padding around it to create the space between one listview and another. You also need to make the layout where the listviews are setup scrollable.
I would personally setup a fragment for each listview to be able to load more data in each list.
Hope this helps. :)

Related

How to divide expandable listview in 2 section with group header using separator

I am using expandable listview to get sub-menu on click of menu. I want to create two different section in expandable listview exactly like menu using separator.
I am using -
MainActivity
ExpandableListAdapter
listheader
list_submenu
Any help will be appreciated.
Thanks in advance.
Firstly, I would recommend you migrate to recyclerView cause nobody use ListView nowadays.
If I get you right, you need something like BigNerdRanch's ExpandableRecycler or expandable recycler view.
This is 2 library, which very easy to use in your app. In some of projects, we used expandableRecycler from the Big Nerd Ranch. Easy, fast, and comfortable. Second one, didn`t try yet.
To divide views with separator, you might be want to use DividerItemDecoration from support lib.
If, for some reason you still want to use listView - you can try tutorial here
Regards.

Android List view row move vertical

I want to create List view row animation like below . I want to move row from one list view to other list view. Both list view are in same activity.
Anyone can give me idea how I can do this.
First of all because you mentioned "ListView":
In my opinion the best way to perform dynamic "lists" in android is to use to android-given class
RecyclerView.
It's easy to use like a normal ListView but like I said before it handles dynamic data.
Moreover it has some support librarys like ItemTouchHelper to drag/drop and swipe items in the list around. Its very easy to expand your RecyclerView with this upgrade. Here is a good tutorial:
Tutorial.
I would like to give you two ideas how I would proceed to implement such a list like the example of your post:
1) (Recommended) Search on Github or similar sites for 3rd library parties that already solved this.
2) Use the RecyclerView with the ItemtouchHelper-Upgrade i mentioned above and try to expand it with two lists. When an item is onMove() set the visibility of the first list on GONE and the second on VISIBLE. Now you only have to add the data of your item to the second list and remove it from the first. Then use notifyDataSetChanged() on both lists and your done.
I dont know how difficult it will be to implement it but thats the only way I know how you can do that and how the programmers of your example could have done it.

Whats the best way to put a customized scrollable list in android studios?

I'm trying to make a android app with a scrollable list like this one...
When I made this app in iOS, I used a UICollectionView. What`s the best way to make this in android studios?
I tried using a list view, but I can't seem to customize it to my needs?
Any Ideas?
ListView was a great way to start and it is customizable to your needs.
However I would recommend to use RecyclerView which works almost on the same principle as ListView but it is a newer concept in Android. It handles the usage of the ViewHolder pattern for you which makes everything super easy.(With ListView, you would've had to implement your own ViewHolder pattern)
All you need to do is to have the RecyclerView in your activity/fragment as the view to hold your data. Then, the key component is to implement the RecyclerView's Adapter which will handle the inflation and setup of each list item.
Here is a really great and short tutorial to get you started with RecyclerView.
If you're done with that here is a bit more advanced video material on RecyclerView from Dave Smith explaining a lot of ways on how to understand and use RecyclerView in your apps.
A ListView fed by an ArrayAdapter of custom objects can do the job.
You might have a class that contains the text and the image of a single item.
Then you can create an ArrayList with items of that class, where you put in all the data.
This ArrayList can be used as dataset for a custom ArrayAdapter, which overrides the getView()-method.
The getView()-method must inflate the xml-layout for each item and attach the data from the ArrayList to the inflated view.
You might want to implement the Viewholder-pattern to achieve a good performance and avoid unnecessary inflations and getViewByID()-calls.
You can also use the new CardView, which can make it a lot easier, since it is made for the new material design in android 5, which looks similar to your item list.

How to have sections in navigationDrawer

I am trying to make a navigationDrawer in Android v4.0+ to be exactly like in this example in the official documentation of android.
However I do not find any documentation how to achieve this. All I can find is telling me to extend the ListView, but that just sounds weird as it looks like the native android classes should have this kind of functionality.
I think you are looking for "ListView header items". One way to achieve such layout is to let your (custom) adapter know that the items at specific positions (or some other criteria) have to be displayed with different layout and populate a different view for those items in it's getView method.

How to make a ListView with draggable items?

I was looking for a ListPreference in which the user can change the order of items from a list. The items would be draggable and can be re-ordered by the user.
I saw this in my custom ROM (and I'm almost sure I saw it in Cyanogenmod) for the QuickPanel. Here's a screenshot to get the idea through:
I know how I can make custom ListView items and set the icon to indicate that the items are draggable, but I don't know how to make them draggable, and change the order accordingly. As for saving them in the preferences, I found this which could be implemented easily.
PS: I know Cyanogenmod is open-source, but I couldn't find the source for this particular thing :( The closest I could get was this, which should be somewhere near the other screen...
Thanks in advance for any tip about this.
UPDATE: I ended up using the files from the accepted answer, with additions and modifications. I am listing them here for further reference.
Use a custom Adapter (ArrayAdapter in my case), to implement the visual feedback that this item is draggable, which is an ImageView near the TextView. This is optional.
Set a DragListener and RemoveListener to update the list accordingly. The ListView does not do that automatically. And it depends on the Adapter you are using.
There was a line that casted a View to a ViewGroup, it made some errors, so I removed the cast without any issue, it was not needed. (in the onInterceptTouchEvent method).
Change mRemoveMode = 1; in the constructor of TouchInterceptor, or one of: FLING = 0; SLIDE = 1; TRASH = 2;. I think for TRASH, a resource should be available too.
I actually took the file not from the answer's link but from the Cyanogenmod one, which I already had, but I guess these files were the same.
These are the actual files in the project (at r12, at the time of writing):
The Preference using this ListView
The ListActivity with the listeners and the Adapter
The actual ListView
I hope it helps somebody else :)
There is no built-in widget to do this, but you may want take a look at the custom implementation used by the AOSP music player to allow for re-ordering of songs in playlists.
TouchInterceptor.java
That's the class which is extending ListView and is responsible for handling all of the MotionEvents and re-ordering its items, as well as detecting swipes for deleting items. You can see it implemented into an activity here in the TrackBrowserActivity.java class.
It has three interfaces you should also be aware of: DragListener, DropListener, and RemoveListener. You can use these interfaces to provide it callbacks to fire for those events, so that you can update changes made to the list order to your SavedPreferences (since the ListView will not handle that for you).
You can easily extend or modify the TouchInterceptor class to add additional functionality since the low-level stuff is all there for you.

Categories

Resources