How to go about extracting data from an api website? - android

I have made an app where it opens up an online api(?) database. I used the ListView widget where each entry (name of something) clicks onto a new activity. I would like to know how to go about extracting data from the database and putting it in my app for example; if I were to get reviews about a shampoo showing on the page and also a picture of the shampoo etc.
Sorry if I make no sense.

It would have helped if you post some of your code.
According to what I understood is that you want to download data from server and show it into your list view.
What you can do is you can hit API in Asynctask. Put each item data like text, image URL etc into one bean class (setter getter) and add that bean into your list attached to your adapter.
Then you can call notifyDataSetChanged() on your adapter.

Related

How to recuperate comment with the position of item recyclerView

I'm a beginner in developing android
I create a news feed where you can comment on posts, to do this I use firebase as a database and I use FirebaseRecyclerAdapter and FirebaseRecyclerOptions
I want the user to click on the "Comment" button of the first RecyclerView
The second RecyclerView displays the comments according to the post clicked.
I have no idea how to do this, knowing that I tried by capturing the position of the post.
Thank you. Thank you.
The first thing you'll need to do is record what pot the user clicked on. If you're using the Realtime Database, I recommend doing that by recording the key of the item that they clicked on. For some hints on how to do that, see:
Retrieving the Firebase key from onItemClick in FirebaseListAdapter
How to get obj key from FirebaseListAdapter on Item Click. FirebaseUI
Next up, you need to pass that key to the second recycler view somehow.
If the two recycler views are in the same activity, you can use a member field to store the comment that was clicked.
If the two recycler views are in separate activities, you can store the key in Android's shared preferences. For more on this data transfer mechanism, see:
SharedPreferences in the Android reference documentation
How to use SharedPreferences in Android to store, fetch and edit values
Finally, you'll need to use the key to load the comments for that specific post. This depends on your exact data structure, but I recommend starting with the documentation on working with lists of data or FirebaseUI, similar to what you likely already have.

How to structure my Android/Sugar app?

Could you give me some advice and answers for my questions about my app?
In my application, I have two activities: first contain a ListView. Every item in listview is filling up with Database data. Second activity includes webView. I am going to use a Sugar ORM as a database. Part of the data will show on the first activity (name, image) and part in the second activity (link for YouTube).
For download and caching images from web I will use a Picasso framework.
1) What kind of adapter should I use for my listView?
2) I didn't find in Sugar's documentation examples of how I can separately query data from Database. Like, I need some part to show in first activity and another part of data in second activity, but in official documentation I have only found this example "Load Entity"
Book book = Book.findById(Book.class, 1);

Session state of ListView

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

How to edit and refresh JSON data in an Android activity?

My Android application utilizes a backend API highly; basically, all of the information is queried from web server and rendered on Activities. So far, I've designed the application to be "read only".
For example, MainActivity first queries server for JSON data and shows the data in a listview. User can open a specific list item by clicking on it. The JSON data for an item is passed to the new activity (SubActivity) as a String representation of a JSONOBject (data.getObject(listItemPosition).toString()), so that no new query to the server need to be made.
However, now I'm facing a challenge as the second part of the application is under development: how to refresh data after it has been modified by user in an Activity. Lets say for example, MainActivity has a listing of images with image comment, and SubActivity shows single image, comment, and some additional information. Now I want to develop a function where user can edit the image comment in the SubActivity.
How should I deal with refreshing the data in MainActivity & SubActivity? Should I edit JSON objects directly (hard from SubActivity)? Should I somehow notify the MainActivity to reload the data? Any other best practices?
if you are using arraylists and customarrayadapters then yes you can notify the data object (and UI object) to refresh itself and update the view
you can edit JSON objects directly, its not like they are sacred, but JSONArrays can be kind of slow.
you can notify activities by doing startActivityforResult method and onActivityResult methods
do you need to update the server with this information? just make a new api call on the server that accepts this information

How do I do a lazy load of images in ListView from PHP server to Android

I am new to android & exploring it.I need to load image of User dynamically in my list shown below
list of Users!
I use one static image to show as user image from my resource folder. this list is dynamic & get change as my location get change but only when i refresh it.
AddObjectToList(jFan_Data.getString("uniqid").toString(),R.drawable.ic_add, jFan_Data.getString("name"), jFan_Data.getString("distance"));
on click of the list item need to display the complete profile of user. i succeed to show complete profile on click i need to show image of user here as well
user_profile!
How i get the data from php(Please gone through) -> android List View having jsonObject
now how i get images of users from my php server... would greatly appreciate any sample code,scripts, and pointers to where I could find more information to better understand the inner working. Also, pretty much interested to know how i use other framework or is there are better frameworks to do what I want to, I am happy to learn about that!!!

Categories

Resources