android - App "lost property office" with ViewPager, Fragment, ListView, JSON -


i'm doing lost property office application. consists of four tabs, each tab must display announcement feed uploaded users. clicking on particular item opens new activity derive more information.(well, sort of news feed). take data api site in form of json.
did 4 tabs using viewpager, fragment. image fragments

have tried place every fragment listview , display data json asyntask. , caused asynctask each fragment called same json in first fragment. may not right.

so, please tell me correct move.

  1. what used display data listview json
  2. how display information on new activity opens when press listview item?
  3. send fragment on intent or download json again?
  4. how realize adding ads user?

if possible, write steps. thank much, glad of help.

p.s sorry bad english

first of can use simple list adapter able put json data listview, can see tutorial of here.

second able see details item in list view can use onlistitemclick, extending listactivity. example of doing be:

mylistactivity.java

public class mylistactivity extends listactivity { // . . .      protected void onlistitemclick(listview l, view v, int position, long id) {          //handle list click here          intent = new intent(this, listdetails.class);          //convert position int string pass intent          value = string.valueof(position);          //put value intent          intent.putextra("key", value);          //start activity here          mylistactivity.this.startactivity(intent);      } } 

listdetails.java

public class listdetails extends appcompatactivity {     @override     protected void oncreate(bundle savedinstancestate) {          super.oncreate(savedinstancestate);          //gets value sent intent          intent intent = getintent();          final string helpview = intent.getstringextra("key");          // . . . } 

this assuming using listactivity make list , depends on sort of information want display, if want display data, pass json data string through intent, in example above.

thirdly if want keep json data can pass along intent , when user presses back, pass original activity once again through intent. if want re-download json data, can, save users mobile internet connection going on (especially large json files repeatedly), in not recommend using option. if want download json data again, need use asynctask download data, not disrupt user interface , raise error when try (believe me, have pulled hair out on this). example of asynctask (from android project working on, uses google maps calculate route):

private class readtask extends asynctask<string, void, string> {     @override     protected string doinbackground(string... url) {         string data = "";         try {             httpconnection http = new httpconnection();             data = http.readurl(url[0]);         } catch (exception e) {             log.d("background task", e.tostring());         }         return data;     }      @override     protected void onpostexecute(string result) {         super.onpostexecute(result);         log.i("log","parser task started");         log.i("log",result);         new parsertask().execute(result);     } }  private class parsertask extends         asynctask<string, integer, list<list<hashmap<string, string>>>> {      @override     protected list<list<hashmap<string, string>>> doinbackground(             string... jsondata) {          jsonobject jobject;         list<list<hashmap<string, string>>> routes = null;          try {             jobject = new jsonobject(jsondata[0]);             pathjsonparser parser = new pathjsonparser();             routes = parser.parse(jobject);         } catch (exception e) {             e.printstacktrace();         }         return routes;     }      @override     protected void onpostexecute(list<list<hashmap<string, string>>> routes) {         //process json data here     } } 

you place inside activity, adding in necessary processing json data inside onpostexecute in parsertask. download json data, call (replacing url url getting json data):

string url = "http://www.example.com" readtask downloadtask = new readtask(); downloadtask.execute(url); 

edit: lastly show latest or important/relevant lost property adverts, can once again use json backend website. in php can customise server responses, sending json responses depending on values in (?thisistheget=blahblahblah). add advertisements can create seperate activity, edittexts etc, create form, send data through request backend server (where json held), server can update advertisement list. once again can use asynctask send request server, perhaps using methods above send server success of adding of advertisement. example of form (xml) be:

activity_add_advertisement.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     app:layout_behavior="@string/appbar_scrolling_view_behavior"     tools:context="your.activity.class.root.activityaddadvertisement"     tools:showin="@layout/activity_add_advertisement"     android:id="@+id/llmaincontent"     android:orientation="vertical"     >     <edittext     android:layout_width="wrap_content"     android:layout_height="wrap_content"      android:id="@+id/edittext1"/>     <edittext     android:layout_width="wrap_content"     android:layout_height="wrap_content"      android:id="@+id/edittext2"/>     <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"      android:id="@+id/submitbutton"/> </linearlayout> 

then set on click listener button being pressed inside activity:

activityaddadvertisement.java

public class activityaddadvertisement {     // . . .     button submitbutton;     @override     protected void oncreate(bundle savedinstancestate) {         // . . .         submitbutton = (button) findviewbyid(r.id.submitbutton);         submitbutton.setonclicklistener(new view.onclicklistener() {               @override               public void onclick(view view) {                    //call methods above send request url, contents of edit texts in request               }     } } 

you can add more edittexts , other elements , inside contents inside request. server edit json include new advertisements. php won't hard, if need tutorials on php, w3schools has tutorials , examples use.

further reading: android intents


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -