3

How to convert ARGB(255 0 255 0) color to HEXADECIMAL color. I have ARGB color in database and I retrieve using webservices in JSON format.
I want to put color in the text field TAG_DIFF_P (R.id.l7)

here it my code, how to add color in background in the text field

try {

        JSONObject json1 = jParser.getJSONFromUrl(myUrl);
        // Getting Array of Contacts
        JSONArray list = json1.getJSONArray(TAG_JSONDataResult);


        // looping through All Contacts
        for(int i = 0; i < list.length(); i++){
            JSONObject c = list.getJSONObject(i);


            String GRPNAME = c.getString(TAG_GRPNAME);
            String QTY = c.getString(TAG_QNT);
            String BUDGET = c.getString(TAG_BUDGET);
            String STOCK = c.getString(TAG_STOCK);
            String DIFF = c.getString(TAG_DIFF);
            String DIFF_P = c.getString(TAG_DIFF_P);                
            String COLOR = c.getString(TAG_COLOR);


            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value

            map.put(TAG_GRPNAME, GRPNAME);
            map.put(TAG_QNT, QTY);
            map.put(TAG_BUDGET, BUDGET);
            map.put(TAG_STOCK, STOCK);
            map.put(TAG_DIFF, DIFF);
            map.put(TAG_DIFF_P, DIFF_P);


            // adding HashList to ArrayList
            contactList.add(map);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    /**
     * Updating parsed JSON data into ListView
     * */
     ListAdapter adapter = new SimpleAdapter(this, contactList,
            R.layout.list_item,
            new String[] {  TAG_GRPNAME, TAG_QNT, TAG_BUDGET, TAG_STOCK, TAG_DIFF, TAG_DIFF_P, },
            new int[] {
                     R.id.l2, R.id.l3, R.id.l4, R.id.l5, R.id.l6, R.id.l7});



            lv2.setAdapter(adapter);



}
ibu
  • 577
  • 4
  • 9
  • 24
  • Could you please refer this link http://stackoverflow.com/questions/8633214/how-to-convert-rgb-value-to-hexadecimal-value-with-alpha-like-0xffffffff – Veera Jul 19 '13 at 06:40
  • @Veera how to i split it it coming from database and i tag the string variable – ibu Jul 19 '13 at 06:50

2 Answers2

7

I think your json should has it as String. If it is so you can try this

String hex = String.format("#%02x%02x%02x", r, g,b);
Chintan Rathod
  • 25,864
  • 13
  • 83
  • 93
Veera
  • 1,775
  • 2
  • 15
  • 19
1

Check this Documentation on Color class

http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)

Color color = Color.parse("#AARRGGBB");

If you have the colors in decimal, you can use.

String hexValue = Integer.toHexString(255)
Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68