title: Set listview rows visibility by its content
body: <p>I am an amateur Andriod programmer and my app shows a JSON string into a  listview. This is the JSON object:</p>
  
  <pre><code>    {"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"}]}
  </code></pre>
  
  <p>I managed to put the JSON into the listview using a simple adapter and a JSON parser and the result can be seen on this image:</p>
  
  <p><a href="http://imgur.com/cnlBlpm" rel="nofollow">http://imgur.com/cnlBlpm</a></p>
  
  <p>However, i want it to look like this:</p>
  
  <p><a href="http://imgur.com/p2qzmBz" rel="nofollow">http://imgur.com/p2qzmBz</a></p>
  
  <p>I like Cyril Mottier's suggestion about using the visibility property of the View class and setting the rows GONE when repeated, but the code that he suggests is for static data:</p>
  
  <p>This is the code for the JSON Parser:</p>
  
  <pre><code>    public class JSONParser {
      /** Recibe un JSONobject y retorna una lista */
      public List&lt;HashMap&lt;String,String&gt;&gt; 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 with the array of json object
      * where each json object represent a country
      */
      return getDatos(jDatos);
      }
  
      private List&lt;HashMap&lt;String, String&gt;&gt; getDatos(JSONArray jDatos){
      int datoCount = jDatos.length();
      List&lt;HashMap&lt;String, String&gt;&gt; datoList = new ArrayList&lt;HashMap&lt;String,String&gt;&gt;();
      HashMap&lt;String, String&gt; dato = null;
  
      /** Taking each country, parses and adds to list object */
      for(int i=0; i&lt;datoCount;i++){
          try {
              /** Call getCountry with country JSON object to parse the country */
              dato = getDato((JSONObject)jDatos.get(i));
              datoList.add(dato);
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  
      return datoList;
      }
  
      /** Parsing the JSON object */
      private HashMap&lt;String, String&gt; getDato(JSONObject jDato){
  
      HashMap&lt;String, String&gt; dato = new HashMap&lt;String, String&gt;();
      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;
      }
      }
  </code></pre>
  
  <p>And this is the main activity:</p>
  
  <pre><code>    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 &gt; 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 AS titulo, LC.nombrecombo AS NombreLinea,(Select Sum(Precioventa1) as Precio from productos where Codigo in (Select                 IdProducto from listacombodetalle LCD where LCD.idcombo = Lc.Id)) as Monto FROM   LISTATITULO LT, LISTACOMBO LC where  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&lt;String, Void, SimpleAdapter&gt;{
  
      JSONObject jObject;
      /** Doing the parsing of xml data in a 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&lt;HashMap&lt;String, String&gt;&gt; datos = null;
  
          try{
              /** Getting the parsed data as a List construct */
              datos = jsonParser.parse(jObject);
          }catch(Exception e){
              Log.d("Exception",e.toString());
          }
  
          /** Keys used in Hashmap */
          String[] from = {"TITULO","NOMBRELINEA","MONTO"};
  
          /** Ids of views in listview_layout */
          int[] to = {R.id.textViewT,R.id.textViewR,R.id.textViewP};
          /** Instantiating an adapter to store each items
          *  R.layout.listview_layout defines the layout of each item
          */
          SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), datos, R.layout.lv_item, from, to);
  
          return adapter;
  
      }
  
      /** Invoked by the Android system on "doInBackground" is executed completely */
      /** This will be executed in ui thread */
       @Override 
       protected void onPostExecute(SimpleAdapter adapter) {
  
          /** Getting a reference to listview of main.xml layout file */
          ListView listView = ( ListView ) findViewById(R.id.lv_datos);
  
          /** Setting the adapter containing the country list to listview */
          listView.setAdapter(adapter);
  
      }
  
  
  }
  }
  </code></pre>
  
  <p>This is the XML who fill the listview</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;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"/&gt;
  
      &lt;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" /&gt;
  
      &lt;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" /&gt;
  
  
      &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Any suggestion on how to hide the repeated rows? And sorry about the links, im new.</p>
  
  <p>Thanks in advance!</p>