title: Change TextView background color in ListView with simple adapter
body: <p>I have a ListView which displays a list with two TextViews. On one of them, I want to apply a specific color. All the data (and colors) are provided by a Json file from web service.</p>
  
  <p>I use a simple adapter which I want to use. Could someone indicate how to put the specific color for each item?</p>
  
  <p>Here is my class:</p>
  
  <pre><code>public class NetworkTimeTableFragment extends Fragment {
  
      private ProgressDialog pDialog;
  
      private static String mylat;
      private static String mylng;
  
      // JSON Node names
      private static final String TAG_NAME = "shop_name";
      private static final String TAG_SHORT = "shop_address";
      private static final String TAG_ID = "shop_url";
      private static final String TAG_COLOR = "feuilletez";
      TextView shop_address;
      TextView shop_name;
      TextView shop_url;
      ImageButton feuilletez;
      private ListView list;
  
      // Hashmap for ListView
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; oslist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      public NetworkTimeTableFragment(){}
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_timetable, container, false);
  
          // Calling async task to get json
          new GetJson().execute();
  
          return rootView;
      }
  
      /**
       * Async task class to get json by making HTTP call
       */
      private class GetJson extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
  
              // Showing progress dialog
              pDialog = new ProgressDialog(getActivity());
              pDialog.setMessage("Loading...");
              pDialog.setCancelable(false);
              pDialog.show();
  
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              // Creating service handler class instance
              ServiceHandler sh = new ServiceHandler();
  
              String myurl = "routes.json";
  
              // Making a request to url and getting response
              String jsonStr = sh.makeServiceCall(myurl, ServiceHandler.GET);
  
              JSONArray array = null;
              try {
                  array = new JSONArray(jsonStr);
              } catch (JSONException e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
              try {
                  for (int i = 0; i &lt; array.length(); i++) {
                      JSONObject jsonObject = array.getJSONObject(i);
                      String id = jsonObject.getString("id");
                      System.out.println("id ---&gt;" + id);
                      String url = jsonObject.getString("url");
                      System.out.println("url ---&gt;" + url);
                      String created_at = jsonObject.getString("created_at");
                      System.out.println("created_at ---&gt;" + created_at);
                      String updated_at = jsonObject.getString("updated_at");
                      System.out.println("updated_at ---&gt;" + updated_at);
                      String short_name = jsonObject.getString("short_name");
                      System.out.println("short_name ---&gt;" + short_name);
                      String long_name = jsonObject.getString("long_name");
                      System.out.println("long_name ---&gt;" + long_name);
                      String desc = jsonObject.getString("desc");
                      System.out.println("desc ---&gt;" + desc);
                      String type = jsonObject.getString("type");
                      System.out.println("type ---&gt;" + type);
                      String type_name = jsonObject.getString("type_name");
                      System.out.println("type_name ---&gt;" + type_name);
                      String color = jsonObject.getString("color");
                      System.out.println("color ---&gt;" + color);
  
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                      map.put(TAG_NAME, long_name);
                      map.put(TAG_SHORT, short_name);
                      map.put(TAG_COLOR, color);
                      map.put(TAG_ID, id);
                      oslist.add(map);
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
  
              list = (ListView) getActivity().findViewById(R.id.list);
              ListAdapter adapter = new SimpleAdapter(
                      getActivity(),
                      oslist,
                      R.layout.listview_routes_row,
                      new String[]{TAG_NAME, TAG_SHORT, TAG_COLOR},
                      new int[]{R.id.long_name, R.id.short_name});
  
              list.setAdapter(adapter);
  
              list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                          int position, long id) {
                      //  Intent intent = new Intent(NewsActivity.this, NewsActivity.class);
                      //intent.putExtra("shopurl",oslist.get(+position).get(TAG_URL));
                      // overridePendingTransition(R.anim.animationin, R.anim.animationout);
                      //  startActivity(intent);
                  }
              });
  
              // Dismiss the progress dialog
              if (pDialog.isShowing())
                  pDialog.dismiss();
          }
      }
  }
  </code></pre>