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.
Related
My problem is simple: I need to make a layout similar to android.R.layout.simple_expandable_list_item_1 which can fit more than one textview in the layout, as well as show the little '>' symbol that indicates that the tab is expandable.
How can this best be accomplished? My first thought was to use the layout as a background of a linear layout with two textviews in it, but I can't seem to make that work.
Vogella has a pretty good tutorial on how to achieve custom list views through Adapters.
Basically, what you do is you create a Layout with the looks you want for the list items and then you extend an adapter (ArrayAdapter for instance), see section 4. Then, in your activity, you create an instance of your Adapter implementation and populate it from an Array containing the data for the list.
Also have a look at the Developers site for how to make the list scroll smoothly with the ViewHolder pattern.
And if you feel you need more info on the expandable part maybe the hive can help.
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.
I would like to have a few similar expandable listviews in my android application across a few activities. They all have the same content, but use different designs. Some have buttons for example, and some not.
I would even want to have three expandable listviews that share everything except the background color for each cell.
Anyways, having a unique adapter for each listview seems like a bad design practice as they all very similar. I was thinking of making an abstract adapter and than extending it for every listview, would that work? Is there any other approach?
Thank you.
Having a unique adapter for each listview seems like a bad design practice as they are all very similar.
That is correct. Duplicated code is almost always a sign of bad code design.
I was thinking of making an abstract adapter and then extending it for every listview, would that work?
Yes.
Is there any other approach?
Yes. E.g. if you want to have an adapter that supports different backgrounds, your adapter should take a background resource/color as constructor parameter. This approach fits for minor changes. If you want to have some non-expandable and some expandable listviews I would favor the inheritance approach.
The problem is that some of my listviews would be expandable, so I could not use Recycler View.
Recyclerviews are a better design choice than listviews. Creating expandable ones isn't too hard, see Expandable list with RecyclerView?.
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.
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.