I have an app with a list of articles loaded with data from a JSON (code, description, price location) within the list there are articles that have promotions and others do not.) My idea is to change color to the ranges that have promotions something similar with this image ...
There is my code, I filtered the result of the JSON of all the articles that have promotions, then I do not know how to change those ranges in another color ..
protected String doInBackground(String... strings) {
prod = new ArrayList<>();
lista_eligida = (ListView) findViewById(R.id.lista);
String url = "http://danbijann.freeiz.com/tareas.json";
HttpHandler sh = new HttpHandler();
JSONObject jsonStr = sh.makeServiceCall(url);
try {
JSONObject jsonObj = new JSONObject(String.valueOf(jsonStr));
Log.e("JSON", String.valueOf(jsonStr));
JSONArray contacts = jsonObj.getJSONArray("PEDIDOS");
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
String codig = c.getString("codigo");
String des = c.getString("descrip");
String prec = c.getString("precio");
String cantidad = c.getString("cantidad");
String ubica = c.getString("ubica");
String prueba = "";
if(objJson.has("prueba") && !objJson.isNull("prueba")){
prueba = c.getString("prueba");
}
String promocion = "";
if(objJson.has("promocion") && !objJson.isNull("promocion")) {
promocion = c.getString("promocion");
}
String prueba2 = "";
if(objJson.has("prueba2") && !objJson.isNull("prueba2")) {
prueba2 = c.getString("prueba2");
}
HashMap<String, String> contacto = new HashMap<>();
contacto.put("codigo", codig);
contacto.put("descrip", des);
contacto.put("precio", prec);
contacto.put("cantidad", cantidad);
contacto.put("ubica", ubica);
contacto.put("preuba", prueba);
contacto.put("promocion", promocion);
contacto.put("prueba2", prueba2);
Log.d("ADAP", codig);
Log.d("ADAP", des);
Log.d("ADAP", prec);
Log.d("ADAP", cantidad);
Log.d("ADAP", ubica);
prod.add(contacto);
}
} catch (final JSONException e) {
e.getMessage();
}
return null;
}
protected void onPostExecute(String result) {
if (pDialog.isShowing())
pDialog.dismiss();
super.onPostExecute(result);
final ListAdapter adapter = new SimpleAdapter(Prueba.this, prod,
R.layout.item_carrito, new String[]{ "codigo", "descrip", "precio", "cantidad","ubica","prueba","promocion","prueba2"},
new int[]{R.id.txtcodigo, R.id.txtdescrip, R.id.txtprecio, R.id.cantidad, R.id.txtubica, R.id.txtprueba, R.id.txtpromo, R.id.txtprueba2});
lista_eligida.setAdapter(adapter);
registerForContextMenu(lista_eligida);
}