android - Set listview rows visibility by its content -


i amateur andriod programmer , app shows json string listview. json object:

    {"datos":[{"titulo":"prueba1","nombrelinea":"corte caballero","monto":"12.84"},     {"titulo":"prueba1","nombrelinea":"secado","monto":"8.56"},     {"titulo":"prueba1","nombrelinea":"peinado caballero","monto":"0"},     {"titulo":"prueba2","nombrelinea":"lavado keras","monto":"7.49"},     {"titulo":"prueba2","nombrelinea":"mascara keras","monto":"10.70"},     {"titulo":"prueba3","nombrelinea":"mechas corto","monto":"6.42"},     {"titulo":"prueba3","nombrelinea":"mechas largo","monto":"10"}]} 

i managed put json listview using simple adapter , json parser , result can seen on image:

http://imgur.com/cnlblpm

however, want this:

http://imgur.com/p2qzmbz

i cyril mottier's suggestion using visibility property of view class , setting rows gone when repeated, code suggests static data:

this code json parser:

    public class jsonparser {     /** recibe un jsonobject y retorna una lista */     public list<hashmap<string,string>> parse(jsonobject jobject){      jsonarray jdatos = null;     try {         /** recupera todos los elementos en el arreglo 'datos' */         jdatos = jobject.getjsonarray("datos");     } catch (jsonexception e) {         e.printstacktrace();     }     /** invoking getcountries array of json object     * each json object represent country     */     return getdatos(jdatos);     }      private list<hashmap<string, string>> getdatos(jsonarray jdatos){     int datocount = jdatos.length();     list<hashmap<string, string>> datolist = new arraylist<hashmap<string,string>>();     hashmap<string, string> dato = null;      /** taking each country, parses , adds list object */     for(int i=0; i<datocount;i++){         try {             /** call getcountry country json object parse country */             dato = getdato((jsonobject)jdatos.get(i));             datolist.add(dato);         } catch (jsonexception e) {             e.printstacktrace();         }     }      return datolist;     }      /** parsing json object */     private hashmap<string, string> getdato(jsonobject jdato){      hashmap<string, string> dato = new hashmap<string, string>();     string nombre = "";     string precio="";     string tipo="";      try {         tipo = jdato.getstring("titulo");         nombre = jdato.getstring("nombrelinea");         precio = jdato.getstring("monto");          dato.put("titulo", tipo);         dato.put("nombrelinea", nombre);         dato.put("monto", precio);      } catch (jsonexception e) {         e.printstacktrace();     }     return dato;     }     } 

and main activity:

    public class mainactivity extends activity {  @suppresslint("newapi") @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.l1);     if (android.os.build.version.sdk_int > 9) {         strictmode.threadpolicy policy = new                  strictmode.threadpolicy.builder().permitall().build();         strictmode.setthreadpolicy(policy);     } } private string xhttppost(string targeturl, string variable, string valor){     string urlparameters = "";     url url;     httpurlconnection connection = null;       try {         //crear parametros del post         urlparameters = variable + "=" + urlencoder.encode(valor, "utf-8");         //crear conexion                     url = new url(targeturl);         connection = (httpurlconnection)url.openconnection();         connection.setrequestmethod("post");         connection.setrequestproperty("content-type", "application/x-www-form-urlencoded");          connection.setrequestproperty("content-length", "" + integer.tostring(urlparameters.getbytes().length));         connection.setrequestproperty("content-language", "en-us");            connection.setusecaches(false);         connection.setdoinput(true);         connection.setdooutput(true);          //send request         dataoutputstream wr = new dataoutputstream   (connection.getoutputstream());         wr.writebytes (urlparameters);         wr.flush ();         wr.close ();          //get response           bufferedreader rd = new bufferedreader(new inputstreamreader(connection.getinputstream()));         stringbuilder sb = new stringbuilder();         string line;         while ((line = rd.readline()) != null) {             sb.append(line);         }         rd.close();          connection.disconnect();         return sb.tostring();      } catch (malformedurlexception e) {         // todo auto-generated catch block         return e.tostring();     } catch (unsupportedencodingexception e) {         // todo auto-generated catch block         return e.tostring();     } catch (protocolexception e) {         // todo auto-generated catch block         return e.tostring();     } catch (ioexception e) {         // todo auto-generated catch block         return e.tostring();      } }  public void onstart(){     super.onstart();     string consulta = "select lt.nombre titulo, lc.nombrecombo nombrelinea,(select sum(precioventa1) precio productos codigo in (select                 idproducto listacombodetalle lcd lcd.idcombo = lc.id)) monto   listatitulo lt, listacombo lc  lt.id = lc.idtitulo";     string z = xhttppost("http://192.168.1.2/android/api/consultarfblp", "query", consulta);     string q = "{" + " \"datos\":" + z + "}";     toast.maketext(this, q, toast.length_long).show();     listviewloadertask listviewloadertask = new listviewloadertask();     listviewloadertask.execute(q); } public class listviewloadertask extends asynctask<string, void, simpleadapter>{      jsonobject jobject;     /** doing parsing of xml data in non-ui thread */     @override      protected simpleadapter doinbackground(string... q) {         try{             jobject = new jsonobject(q[0]);             jsonparser jsonparser = new jsonparser();             jsonparser.parse(jobject);         }catch(exception e){             log.d("json exception1",e.tostring());         }          jsonparser jsonparser = new jsonparser();          list<hashmap<string, string>> datos = null;          try{             /** getting parsed data list construct */             datos = jsonparser.parse(jobject);         }catch(exception e){             log.d("exception",e.tostring());         }          /** keys used in hashmap */         string[] = {"titulo","nombrelinea","monto"};          /** ids of views in listview_layout */         int[] = {r.id.textviewt,r.id.textviewr,r.id.textviewp};         /** instantiating adapter store each items         *  r.layout.listview_layout defines layout of each item         */         simpleadapter adapter = new simpleadapter(getbasecontext(), datos, r.layout.lv_item, from, to);          return adapter;      }      /** invoked android system on "doinbackground" executed */     /** executed in ui thread */      @override       protected void onpostexecute(simpleadapter adapter) {          /** getting reference listview of main.xml layout file */         listview listview = ( listview ) findviewbyid(r.id.lv_datos);          /** setting adapter containing country list listview */         listview.setadapter(adapter);      }   } } 

this xml fill listview

    <?xml version="1.0" encoding="utf-8"?>     <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <textview     android:id="@+id/textviewt"     android:layout_width="match_parent"     android:layout_height="75dp"     android:layout_weight=".6"     android:background="#f00"     android:gravity="left"     android:text="tipo de servicio"     android:textcolor="#fff"     android:textsize="60sp"      android:visibility="visible"/>      <textview     android:id="@+id/textviewr"     android:layout_width="500dp"     android:layout_height="50dp"     android:layout_alignparentleft="true"     android:layout_below="@+id/textviewt"     android:text="renglon"     android:textcolor="#000"     android:textsize="40sp" />      <textview     android:id="@+id/textviewp"     android:layout_width="300dp"     android:layout_height="50dp"     android:layout_alignbaseline="@+id/textviewr"     android:layout_alignbottom="@+id/textviewr"     android:layout_torightof="@+id/textviewr"     android:background="#bababf"     android:gravity="center"     android:text="precio"     android:textcolor="#000"     android:textsize="40sp" />       </relativelayout> 

any suggestion on how hide repeated rows? , sorry links, im new.

thanks in advance!


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -