RecyclerView - Add header based on object field - android

Say I have a RecyclerView and I'm populating it with an object.
And the object has a date field, and when a new date is reached, a standalone header is created with that date, and then the item is added.
The following objects with the same date will not create a new header, unless it's a new date.
Is it possible to do this (maybe using getItemViewType), while also being compatible with ItemTouchHelper?
So, if I remove the last item under a header at runtime, it'll also remove the header?
Also can I make the header not swipeable?
Other SO-posts solutions, as far as I understand, expect that the header information will come as part of the list input, while I want it to be based on the date of the objects.

Related

How to pre-populate Form fields with initial values in Kinetise?

In Kinetise mobile app generator I want to init form fields (like Text Input) with some dynamic (from web service) values. How can I achieve this?
I found the answer myself so I share it if someone have similar problem:
You need to put Form widget into List widget.
Add List widget and connect it to your API exposing those initial values
Reduce items count to 1, disable SHOW MORE
Add Form widget inside that single-item List widget.
edit TextInput of that Form widget and set its initial value being read from proper node of API you pointed to in step 1.
Initial values of other Form fields should be handled accordingly.

Firebase - How to order items?

I'm trying to make a very simple list-based android app.
Is there a easy way to order objects and sort them by date?
My goal is to show the last added item on top of the list.
I've already tried with a client-side solution but it's not efficient.
At the moment i'm using this json data model:
{
id:"",
name:"",
body:"",
date:"date here"
}
Does anyone have and idea on how to solve this?
You must must use orderedByChild by the key of the date you'd like to order the children by. You can then observe the Value or ChildAdded event type of this query to retrieve the children in ascending order of date. To have the most recent first, you must reverse the objects manually client-side. Otherwise, you could prepend a - symbol to all the dates and handle it client side.

Sort listitem in android based on timestamp when using Preference to store data

I am adding new item (OR sorting) in listview at the top using below code
items.add(0, new EntryItem(first, second));
and it works too, but sometimes when two things are triggered at same time, it won't sort particularly. Is there any way to sort listitem based on timestamp. I am using preferences hence for me to fetch timestamp is little difficult and do comparison based on it. Any other suitable way to sort listitems in listview based on timestamp ?

ArrayList with Multiple data

I have a small issue with ArrayList. I have to fetch the document from the server.
The document contains 7 fields of data. I have to show the document names in the list view.
For this I have added different fields data to the different ArrayList. So when I click on the document name, based on the position of the document, I fetched the all fields data from the different Arraylist based on the position.
But Have a small issue using by using the above procedure. Is there any procedure that is not depend on the position, what I want is irrespective of position if I click on the Document,based on the keyword document data to be extract.
Any Help Appreciated.
Thanks in Advance.
I got your point. If you try to manage different ArrayLists then it would be difficult to manage it. I mean if you delete item from particular position from particular ArrayList then you will have to delete items from same position from other ArrayList, if you forgot to do so then it will be unbalanced.
Solution:
Instead feasible solution is to create ArrayList<Object> or ArrayList<HashMap<String,String>>, so your every item is the type of particular object, and every object contains detail and everything of particular items.
For example: ArrayList<Documents>, here ArrayList will contains list of Documents objects, and every objects contains values of 7 fields.
Its simply easy to define Documents class with getter/setter attributes.

Using text field with AdapterView

Is it possible to use AdapterView with text fields in android?
My query returns a set of values and for each I want to place that within a textfield, so that the user may edit the value.
Also, I want to click a button to create a new empty field, so that I may insert a new entry.
If you know of good example, then please let me know!
EDIT 1
I would prefer to use XML to define ui and I found this informations:
"In this case we create a new id called text1. The + after the # in the id string indicates that the id should be automatically created as a resource if it does not already exist, so we are defining text1 on the fly and then using it." Source http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html
Will this + allow me to autocreate as many fields as needed? Is there a way I can generically specify the layout in XML and then create fields adhoc based on db response?
Many thanks,
Mith
Is it possible to use AdapterView with
text fields in android?
Yes. It will be complex for you (and possibly also for the user), so I would not recommend it unless you have a few months' Android programming experience, but it should work.
Also, I want to click a button to
create a new empty field, so that I
may insert a new entry.
That will get a little complicated.
Will this + allow me to autocreate as
many fields as needed?
No, that is not how you use ListAdapters for ListView rows.
Is there a way I can generically
specify the layout in XML and then
create fields adhoc based on db
response?
Use a CursorAdapter.
Here is a free excerpt from one of my books that describes creating custom adapter classes. Here is a sample project that shows creating a custom CursorAdapter to display the results of a database query.

Categories

Resources