updating a fragment to achieve facebook like wall android - android

This is a theoretical question for the time being as I do not have any code as yet.
As far as I understand fragements they are basically a means of displaying results from an activity, what I am trying to achieve is a automatically updating 'wall' like facebook inside my fragmemt.
Currently I query information from my database from my mainactivity before passing the info to my fragement, as it stands I have only retrieved static content to update an Image and TextView like so:
Intent upanel = new Intent(getApplicationContext(), MainActivity.class);
upanel.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
upanel.putExtra("USER_ID",json_user.getString(KEY_UID));
upanel.putExtra("USER_FN",json_user.getString(KEY_FIRSTNAME));
upanel.putExtra("USER_LN",json_user.getString(KEY_LASTNAME));
pDialog.dismiss();
startActivity(upanel);
Now, how would one achieve a 'live' update, for instance a drag up to update like in the facebook app?
What should I be researching to achieve this?
Edit
In the spirit of asking an actual question, how do you update a fragment from a JSON request in real time?

Related

The same activity opened from different activities displays different data

Maybe it is difficult to understand the title but let me explain. So I am working on an sports application. The main idea - I will parse official website which contains match schedule, results, stats, team info etc. Now I am working on the UI before I make functions for parsing and storage of data. It should look something like this:
ActivityTeams will contain the following buttons:
Team 1
Team 2
Team 3
...
For every team make a new activity but inside of these activities I will need the same buttons - Team info, stats, results etc. So it will be appropriate to make these activities only for once and just somehow load different data on them. If the path will be Teams > Team 1> Stats the data on display will be different than if it will be Teams > Team 2> Stats. How can I do this? I understand that I can open the same activity from every other activity I would like to but how to make the function for displaying different data in the same activity depending on the path? Any tips, suggestions? Thanks!
You can achieve this using intents, so go read the android doc.
Android Intents - Tutorial
You can use Intents in Android to switch from one Activity to other and pass some identifier(like Team name or Team id).
Call a Activity on button click and pass the identifier as an Extra in Intent.
Access the Intent Extra you passed in your Activity(which would start on click), and manipulate it with switch
Something like this
//In TeamActivity
Intent i = new Intent(getBaseContext(), TeamActivity.class);
i.putExtra("team_id", 01);
startActivity(i);
//In clicked Activity
int teamId = getIntent().getIntExtra("team_id",00)
switch(teamId){
case 01:
//Make changes for when Team with id 01 is clicked
break;
case 02:
//Make changes for when Team with id 02 is clicked
break;
}

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

Adding more details to FriendPickerFragment in android app

I want to use the FriendPickerFragment but instead of showing only the picture and name i would like to add more details like where he working? where he live?
Do you know how i can do it? and explain? or point me to example.
I look in the web to solution and didn't find something.
Unfortunately Facebook's FriendPickerFragment does not provide any methods to customize information it presents. The most reasonable solution is to create your own fragment with ListView. You should also create list's adapter feeded with GraphUser objects representing user's friends. List of friends can be obtained from server by using Request.executeMyFriendsRequestAsync(Session, com.facebook.Request.GraphUserListCallback) method.

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

Android create favourites issue

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.

Categories

Resources