java - How do I make separators for a ListView with a SimpleAdapter -


i'm new java programming language , i'm trying build app. app has make list of worked hours have been saved in mysql database. found example app, helped me retrieving data database , putting in listview. problem. want put separators in listview.

now, date of worked hours in every item of listview. want date above first item.

i've searched internet way this, didn't me.

this code gets data , puts in listview:

    public class allurenactivity extends listactivity {     string url_all_uren;     string ip;     string proid;     string uid = mainscreenactivity.uid;     string datum;     string datum1;     imageview btntoevoegen; // progress dialog private progressdialog pdialog;       textview tvdatum;  // creating json parser object jsonparser jparser = new jsonparser();  arraylist<hashmap<string, string>>urenlist;      // json node names private static final string tag_success = "success"; private static final string tag_uren = "uren"; private static final string tag_trid = "trid"; private static final string tag_proid = "proid"; private static final string tag_werkzaamheid = "werkzaamheid"; private static final string tag_tijd = "tijd"; private static final string tag_datum = "datum";  // products jsonarray jsonarray uren = null;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.all_uren);      sharedpreferences settings = getsharedpreferences("databaseip", 0);     ip = settings.getstring("ip", "").tostring();     url_all_uren = ("http://"+ip+"/android_connect/get_all_uren.php");       // hashmap listview     urenlist = new arraylist<hashmap<string, string>>();      // loading products in background thread     new loadalluren().execute();      // listview     listview lv = getlistview();       // on selecting single product     // launching edit product screen     lv.setonitemclicklistener(new onitemclicklistener() {          @override         public void onitemclick(adapterview<?> parent, view view,                 int position, long id) {             // getting values selected listitem             string proid = ((textview) view.findviewbyid(r.id.tvproid)).gettext()                     .tostring();             string werkzaamheid = ((textview) view.findviewbyid(r.id.tvwerkzaamheid)).gettext()                     .tostring();             string trid = ((textview) view.findviewbyid(r.id.tvtrid)).gettext()                     .tostring();             // starting new intent             intent in = new intent(getapplicationcontext(),                     allprojectsactivity.class);             // sending pid next activity             in.putextra(tag_proid, proid);             in.putextra(tag_trid, trid);             in.putextra(tag_werkzaamheid, werkzaamheid);             // starting new activity , expecting response             startactivityforresult(in, 100);          }     });  }  // response edit product activity @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     // if result code 100     if (resultcode == 100) {         // if result code 100 received          // means user edited/deleted product         // reload screen again         intent intent = getintent();         finish();         startactivity(intent);     }  }  /**  * background async task load product making http request  * */ class loadalluren extends asynctask<string, string, string> {      /**      * before starting background thread show progress dialog      * */     @override     protected void onpreexecute() {         super.onpreexecute();         pdialog = new progressdialog(allurenactivity.this);         pdialog.setmessage("uren laden...");         pdialog.setindeterminate(false);         pdialog.setcancelable(false);         pdialog.show();     }       /**      * getting products url      * */     protected string doinbackground(string... args) {             // building parameters         list<namevaluepair> params = new arraylist<namevaluepair>();         params.add(new basicnamevaluepair("uid", uid));          // getting json string url         jsonobject json = jparser.makehttprequest(url_all_uren, "get", params);          // check log cat json reponse         log.d("uren: ", json.tostring());          try {             // checking success tag             int success = json.getint(tag_success);              if (success == 1) {                 // products found                 // getting array of products                 uren = json.getjsonarray(tag_uren);                  // looping through products                 (int = 0; < uren.length(); i++) {                     jsonobject c = uren.getjsonobject(i);                      // storing each json item in variable                     string trid = c.getstring(tag_trid);                     string proid = c.getstring(tag_proid);                     string werkzaamheid = c.getstring(tag_werkzaamheid);                     string datum = c.getstring(tag_datum);                     string tijd = c.getstring(tag_tijd);                       // creating new hashmap                     hashmap<string, string> map = new hashmap<string, string>();                      // adding each child node hashmap key => value                     map.put(tag_trid, trid);                     map.put(tag_werkzaamheid, werkzaamheid);                     map.put(tag_proid, proid);                     map.put(tag_tijd, tijd);                     map.put(tag_datum, datum);                       // adding hashlist arraylist                     urenlist.add(map);                 }             } else {                 // no products found                 // launch add new product activity                 intent = new intent(getapplicationcontext(),                         newproductactivity.class);                 // closing previous activities                 i.addflags(intent.flag_activity_clear_top);                 startactivity(i);             }         } catch (jsonexception e) {             e.printstacktrace();         }          return null;     }      /**      * after completing background task dismiss progress dialog      * **/     protected void onpostexecute(string file_url) {         // dismiss dialog after getting products         pdialog.dismiss();         // updating ui background thread          runonuithread(new runnable() {             public void run() {                 /**                  * updating parsed json data listview                  * */                      listadapter adapter = new simpleadapter(                             allurenactivity.this, urenlist,                                     r.layout.list_uren, new string[] { tag_trid, tag_proid, tag_werkzaamheid, tag_tijd, tag_datum},                             new int[] { r.id.tvtrid, r.id.tvproid, r.id.tvwerkzaamheid, r.id.tvtijd, r.id.tvdatum });                      // updating listview                     setlistadapter(adapter);                 }              });      }  }      } 

list_uren.xml

        <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="vertical" >       <textview         android:id="@+id/tvtrid"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:visibility="gone" />      <!-- name label -->      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content" >          <textview             android:id="@+id/tvdatum"             android:layout_width="269dp"             android:layout_height="wrap_content"             android:gravity="center"             android:paddingleft="6dip"              android:textappearance="?android:attr/textappearancelarge"             android:textsize="17sp"             android:visibility="visible" />          <imageview             android:id="@+id/toevoegen"             android:layout_width="25dp"             android:layout_height="25dp"             android:src="@android:drawable/ic_menu_add" />     </linearlayout>      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content" >          <textview             android:id="@+id/tvtijd"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:paddingleft="6dip"              android:text="8:00-12:00"             android:textsize="17sp"             android:textstyle="bold"             android:visibility="visible" />          <textview             android:id="@+id/tvproid"             android:layout_width="138dp"             android:layout_height="wrap_content"             android:layout_marginleft="25dp"             android:paddingleft="6dip"              android:text="project"             android:textsize="17sp" />     </linearlayout>      <textview         android:id="@+id/tvwerkzaamheid"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:paddingleft="6dip"         android:paddingtop="6dip"         android:text="werkzaamheid"         android:textsize="17sp" />          </linearlayout> 

all_uren.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical">     <!-- main listview           give id value list(@android:id/list)     -->      <listview         android:id="@android:id/list"         android:layout_width="fill_parent"         android:layout_height="wrap_content"/>  </linearlayout> 

what best way date separators? thank you.

add @ end of list_uren.xml before closing linearlayout

    <view     android:layout_width="match_parent"     android:layout_height="1dp"     android:background="#666666" /> 

you can change background whatever want.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -