Replace ListView with RecyclerView - android

How can I replace old Listview with Recylerview?
What changes should I keep in mind when replacing Listview with Recyclerview?

The core of the conversion is the Adapter. Better to have it as library because you don't want to create a new one from scratch every time for a different use case.
So, I've created a FlexibleAdapter for all RecyclerView.
Please have a look at the description and full working example: https://github.com/davideas/FlexibleAdapter

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.

How to create the layout for this kind of activity?

How can I display information in the following format? What controls should I use, listView or RecycleView?
Note that the question isn't about this particular activity and how to use it. It's about how to show the information in the same format and how to create the layout for it.
That is a ListView. You would just need a ListAdapter/ArrayAdapter to fill it and that's about it.
You can make exactly the same thing using the layout simple_expandable_list_item_2 in the SimpleAdapter of a ListAdapter (here is how you do it : Displaying kind of static data in ListView)
RecyclerView is of course much better in terms of performance and flexibility. However, ListView is enough in many cases like this one.

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 implement sectioned listview like in youtube app 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. :)

Categories

Resources