Save UI and data in android - android

I am working on a messenger type application,when a user click on a user from chat window I show a blank Layout with a send button and EditText at bottom,now when user type text in Edit Field and click on send I create a dynamic Layout holding some dynamically created other UI component like Label and ImageView etc.now I want to save this UI state when user press back button or home button.I know there is a method for activity like SaveInstance etc it save only data object but here I want to save GUI with data for all chat windows,anyone can guide how I can handle this ?I will be very thankful for guidance. .

You're doing it wrong.
You should be storing your data in some place (in memory, like in a static array somewhere, or in sql if you need to keep it across sessions), and displaying a listView with an adapter on this data. then, when adding data, you only need to notify your adapter to refresh the view.

Related

Android validate items inside RecycleView

I'm having a big form inside a recycleview, with multiple repeating items. Think of it like multiple forms: data of car 1, data of car 2 etc. under each other.
Now I'd like to validate all data before saving. Basically the problem is, that the views might not be visible when the user presses the save button.
What's a working way to do this?
My idea would be to scroll manually to each form viewholder THEN validate those, and just stop at the first invalid cell.
But is there a better way? Because this is a bit hacky to me. Is there a way to force a recycleview to actually create a view without it being visible on screen?
Thanks
You should do your validation things on your dataList, for example you have a big array in your activity and you passed it to your adapter.after user clicks on save button you should start validating process on your list(not your adapter).
for example in your Activity you have an ArrayList of car object (carList) and you passed it to your adapter.after clicking on save button you should do something like this in your activity class:
for(int i=0;i<carList.size();i++)
{
if(!isDataValid(carList.get(i)))
//do your stuff here
}
//notify your adapter here

Get web service display in recyclerview and save to Favorites

I am very new to Android , and I knw a question like this has been asked but I can't seem to understand much from the answers so I thought giving my issue I would get help ,
I am developing an app that gets json feed from Server using Retrofit, Picaso and display in a custom recyclerview and when clicking on the item it opens up a Detail activity (this I have managed to do)
Now I have Two activity one is the main which get the feed stated above and the other is myFavorites activity.
My recyclerview has a like button (heart) I would like that when a user clicks on the like button that particular recyclerview gets sent to favorites activity which also has a recyclerview
And when the user clicks the same likebutton (which will now be red ) it will turn grey and that item sent to favorites will be removed from favorites
I have seen the Shared preferences demo but I don't know if this will work with having a master/ detail activity as I would like the user to still able to click on the item that was. Sent to favorites and view the Detail activity of it
I have also come across Some saying you can save the Favorites to Sqlite and I couldn't really manage to impliment it and been stuck for two weeks now trying every possible trick I can think of
I managed to save the whole list to Sqlite using a tutotial by (Get JSON using Retrofit2 save to DB and display it on RecyclerView ) but thats not wht I wnt , I want the user to independently save data to favorites using a like and unlike button on the recylerview
I Hope my question is understandable please someone help I have been stuck here for along time now

listfragment android layout

I'm trying to create a layout in my fragment that allows a user to enter their workout. The fragment has an ArrayList of sets, and each set consists of an exercise name, sets/reps, and rest time. I can only populate so many sets at the beginning, and want to add a button at the bottom 'add exercise' in case the user wants more exercises than what the loaded layout allows...example..
Ex #1
sets/reps
rest time
Ex#2
sets/reps
rest time
[add exercise]
I tried using a listfragment and an adapter, but im not sure how I can withdraw the data that is entered into the edit text fields and save them for later use. Any help is greatly appreciated, thanks in advance.
Using adapter is a good idea.
Here is one way to achieve your goal:
When person clicks on add exercise button, you should get the new exercise information from the user. You can use Dialog or another activity-screen for that.
Once you got the info(sets/reps and rest time). Go and update the ArrayList that populates the data in the adapter. And when you done call: Adapter.notifyDataSetChanged() this will make the adapter to invalidate the view based on the changes in the data(ArrayList in your case).

How to save a checkbox in dynamic ListView when exiting the app

I am new in Android and I was wondering if there is some way to save the following:
I have a custom adapter which contains a title and a checkbox.
The list is obtained from a database which is always changing so the listView is dynamic.
I cannot use SharedPreference because it only saves the position (and the list is moving) and I would like to find a way to save if the checkbox in each item is enabled or disabled when the user exits the application.
Basically it consist on an app which everybody can accessing a database to insert new values and its values are shown in a ListView in other interface, but the each element of the ListView has an Item with a checkbox and I would like to save the state of this checkbox for each user when user exiting the application.
The fast but heavy solution would be creating a particular database in each device to store all the item that the user read, but I asked to see any other solution.
http://i.stack.imgur.com/eBfls.png
For example, it can be people who did or did not press in the item "sport". So I want to save the state for this people who did it in their devices.
Is cookies a solution?
I did not completely understand the scenario. But you can save them to database in your onPause() method.

How to create a N-level dynamically changing listview

im facing a problem in my project. What im trying to do is,
i need to parse a json reponse to a listview.
While clicking the row i will get some id , and now i need to call another webservice using that id and it should show another list .Suppose i clicked the First row ,ie Board "A". Then the next Listview should be the sublist of A . It might look like the following
A1,A2 etc may or maynot have submenus.
I can get the id of from the clicked row . And if the list is empty means no more submenus.
I dont know how to design this system? Does any one have any idea? Thanks in advance
PS: I will have to make different webservice call to get each submenu that depends on the ID im passing from the listview row click
A few ideas to get you started:
Instead of using ListView, take a look at GridView. ListView does not support more than one column (you have to support that manually) and GridView was introduced for this purpose.
Let's assume your initial list is shown in its own activity. This means you have an activity which queries the webservice on its onCreate() and then displays the results in the ListView/GridView when they are returned asynchronously from the webservice.
It will be convenient to hold the submenu in its own activity. This means you should create another activity for the submenu (maybe it can share code with the first one or even be derived from it to reduce code duplication). This activity will receive in its Intent an argument (take a look at Intent.putExtra and Intent.getExtra) which tells it which row was clicked (it should usually contain the String filter you are about to pass to the webservice). Once this activity is created, in its onCreate it should query the webservice much like the first activity and show its results in its own ListView/GridView.
To connect the two activities you'll need to catch the on click event in the first activity, figure out which row was clicked, and then create an Intent to show the 2nd activity, pass the extra and show it.
This approach will let the user dismiss the 2nd activity using the back key once they're finished with it. Once it's dismissed, the user will be returned to the 1st activity where they can click on a different row.

Categories

Resources