Hi I need a little help with an issue that I have.
I had to build an application which needs to show only a text information and pictures.The content was a lot, that's why instead of creating 200 single activities for very page I create one base activity which content I'm changing everytime depends on which listview item is clicked using putExtra(); and getExtra();. So the problem now is that they want me to create Favourites page, where the users can save some of the information and access them on a single activity.Actually it's really easy to do this using sqlite,but they want from me to finish the application today, within a few hours.My problem is that If i start coding it again and insert all that information in database it will take much more time for me.
So here is a little more explanation :
1.I have base activity with a listview.
2.When user click on listview item I send the content using putExtra in base activity.
So I need to learn how to save the id of listview item or something else and show that content in new Activity. I was thinking of using SharedPreferences but not really sure how to deal with that.
Any suggestions how I can do that...for a few hours.
Thanks in advance!
What kind of content is it? Is it over 200 entries and you don't save them locally?
Just knowing if it's a favorite or not can not be more than one hour job using sqlite. Just keep the id of the content and then a value to see if it's a favorite or not.
Noone will really do that for you since it's obviously your (paid?) job. The fact that you can't do it in time is really not a reason to skip the best option to use.
I would say don't be that optimistic about what you can achieve in which time. Manage your resources better and you will not have that problem.
You can achieve this with sharedpreferences too,but it's not a good idea.
The best way is to do it with database,but it's up to you.
Related
I need a little help with an issue in App Inventor 2. The case is that I have a JSON result that is parsed, and then have it stored in a tinyDB tag as a list (storeparseData).
Problem is that, I have this function done as screen initiates, so to have the tinyDB tag populated with that JSON list and then searched for a specific value on user request.
As the app is running and I input a search criteria, I get the following error "The arguments [empty-string] are the wrong number of arguments for GetValue". I suppose that, it finds nothing yet to be stored in the tinyDB tag to search for, cause the JSON data take some time to be fetched and parsed.
Here is what I have done for now for checking if the stored list is in the tinyDB:
Here I check the stored list in tinyDB for an item:
So how can I check if the tinyDB is populated in this tag with the JSON results list, so I can then have it searched? Is this possible in App Inventor 2?
Please someone advise on this issue with a sample code blocks if possible, or a similar tutorial, if there is any. Thank you all in advance for your answers.
This looks very strange... a complicated if then else structure, loads of empty sockets and your comparison if "storeparsedData" = <empty string> always will be false... obviously this does not make sense...
it looks like you are thinking too complicated?
what about this:
As already recommended in my answer to your other question you should learn how to work with lists...
how to work with lists
how to work with list of lists (pdf) by appinventor.org
see also An example of a complex List of Lists
Also doing some more tutorials might help to learn some more basics...
To answer your question "Can you explain why you've chosen to create an empty list there.": if you are working with lists as in the example and you are trying to read a list from TinyDB, then you also have to think about what should happen, if that tag is not available in TinyDB (for example after starting the app the first time). And for lists, in this case an empty list should be returned. Note: the is list empty? block always expects a list. If you set valueIfTagNotThere to an empty string, then you will get a runtime error...
You can use Clock function to delay the time. Firstly, just set the global DelayCountdown to specific number in "when Screen1.Initialize" part. Then, by using "when Clock1.Timer" function, you just need to add another check whether the DelayCountdown is equal to zero before you do another function.
I am new to Android App development, working on an android app which populate a list of numbers, in a listview dynamically, depending on the choice of the user, but, the moment user closes the App, the items in the listview are lost. How can I maintain the state of the listview?
Examples with code would be highly appreciated.
When I open Activity A, it allows users to add friends, and this friend list is shown in the form of items of listview in the same Activity, however, when I move to Activity B, and then come back to Activity A, this friend list disappears. I need to make sure that this friend list should not be lost while moving between activities. Please help.
I think that for your purpose there are 3 main methods, i'll explain them from the easier to the most difficult (in my opinion).
Text File
A way to do this is to create two methods in a class:
one has to create the text file in the storage if it isn't created before and read that, the other has to append a String to a StringBuilder and write it on the previous text file.
For this method you need the uses-permission of reading and writing to storage.
This link can help you: http://developer.android.com/training/basics/data-storage/files.html
JSON (also XML)
With JSON file you can create a list of objects with your data that you can serialize when you update the list and deserialize when you want to read it. For this purpose you have to study JavaScript syntax or, at least, JSON one.
SQLite Database
Android SDK incorporate a class named SQLiteOpenHelper that you can extend to create a database inside your app.
This link can help you: http://developer.android.com/training/basics/data-storage/databases.html
There are also references saving methods but i think that aren't right for your purpose, they work betters to save something like preferences or single data like last login informations.
I went through your comment. I would personally suggest using SQLiteOpenHelper
You might need to understand the use of SQLite, hence the tutorial
Simple Flow. On your Activity 1 where person Add Friends save it to DB
Then refresh the List from the DB. So when you move to Activity 2 and come back again to Activity 1 your List will refresh from DB. Hence no loss of data as you want.
EDIT
As user wanted to know how to use the ListView with DB.
Following are my suggestion
Sai Geetha
Youtube
First of all I'm not native english speaker so I'm sorry if there is any grammar or spilling mistakes but I'm really trying to do my best here.
OK, I'm developing an application in android system for e-commerce, the user can add any product to sell, but as you know there are many filters questions.
For example if the user want to sell a car he has to select the model and the company of the car, but if he want to sell a mobile then the questions changed to select the storage for example and the model and the company questions will be deleted, so the questions here are dynamic.
I already developed the form using RecyclerView and its look great.
figure1
figure2
figure3
The problem that when I used
notifydatasetchanged
The form data get mixed!
I solved this problem using
notifyItemRangeRemoved and notifyItemRangeInserted
So it's working great, but I still confused why this is happened?
The second problem that is the dynamic form is a fragment called "DynamicFormBuilderFragment" and sometimes I have to replace it with another fragment like "Google Maps fragment" for example the problem that when I call back the "DynamicFormBuilderFragment" all my data is Lost and the form get duplicated!
Like this
figure4
I want to put some codes but really I don't know what to put because they all are too long and complex, but for start I think this problem because I made the RecyclerView.Adapter not static, I will try for now to made it static and see what happens, but I still need your help please.
Thanks for reading and I wish to you a great day and happy coding.
Update
this is my java files and classes
AddAds.class extends ActionBarActivity
DynamicFormBuilderFragment.class extends Fragment // is contain RecyclerView + Adapter + LoadToAdapter + questions classes and it's where dynamic form get build.
GoogleMaps.class extends Fragment
SLOVED!
I Replaced the RecyclerView with the ListView and it's working great now so thanks #greenapps.
I think it's a bug so I will reported to Google.
So I have JSON, I parsed in and it's sitting there. From my code below it looks like I have put everything into an ArrayList but then what? I mean for example I need the "title" of each JSON object to be an onClick on the first page, is that possible?
Essentially my onPostExceute() is empty/not doing much. Eventually I need to separate each object into it's own page via the onlicks I'm mentioning, but I think I can do that by separating the JSONObjects...? guess I'll come to that when I can.
If I want to separate things should I even be using an ArrayList? It's just what I used for a server test I ran with different code.
Would really appreciate some help. Basically stuck at the last hurdle is how I perceive it. Maybe I'm wrong though. The logs see that the JSON is showing up as one big chunk.
Edit: Removed my code, this is more of a theory question. ListView being the best thing to go with.
yes you can make spearate arraylist for them..and can store them in diferent listviews...on google click you can open new listview showing id and link for google ..and same you can do for microsoft and your other trem.And using onItemClick is a gud option,you can easily get the index of item clicked//
I am working a project. I have lots of word text data and don't want to add layout and class for each one. I want to use sqlite, but don't know how. For example, there is a button, id is cat.
When clicking the cat button, a new screen opens and shows information of cat. One layout, one class, but lots of screens. The data must come from sql because there are too many animals.
Thanks in advance.
You have given the answer already yourself: SQL database may be your friend. Work yourself through this tutorial and see how far that brings you. You'll have to manipulate the UI from code, that is doable as well.
Another approach you might want to consider is putting everything in XML into strings.xml file(s). This depends a bit on the size and structure of your data. From code you can reach this using getString( R.id.blah ).
Call other screen passing values.
In the button click do:
startActivity(new Intent(this, SecondScreen.class).putExtra('Identify', 'Value'));
In the Second Screen do:
String value = getIntent().getStringExtra('Identify');
Now, take that value and make the query in SqLite and display the result.