2015-01-21 2 views
0

내 JSONObject 중 하나가 ListView에 표시되는 데 문제가 있습니다. 나는 표준 JSON Parser, Async Task 등을 사용하고 있으며, 하나의 특정 문자열 (합계)을 제외한 모든 것에 대해 정상적으로 작동한다.Android JSONObject 소수점이 표시되지 않음

JSON :

{ 
     "item": "Item name", 
     "quantity": "67", 
     "unit": "m", 
     "total": "603.00" 
}, 

안드로이드 : 여기 내 코드 조각의

if (jsonStr != null) { 
try { 
    JSONObject jsonObj = new JSONObject(jsonStr); 

    items = jsonObj.getJSONArray(TAG_ITEMS); 

    for (int a = 0; a < items.length(); a++) { 
     JSONObject l = items.getJSONObject(a); 

     String item = l.getString(TAG_ITEM_NAME); 
     String unit = l.getString(TAG_UNIT); 
     String total = l.getString(TAG_TOTAL); 
     String quantity = l.getString(TAG_QUANTITY); 

     Log.d("item got: ", "> " + item); 
     Log.d("unit got: ", "> " + unit); 
     Log.d("total got: ", "> " + total); 
     Log.d("qty got: ", "> " + quantity); 

     HashMap<String, String> myItems = new HashMap<String, String>(); 

     myItems.put(TAG_ITEM_NAME, item); 
     myItems.put(TAG_UNIT, unit); 
     myItems.put(TAG_TOTAL, total); 
     myItems.put(TAG_QUANTITY, quantity); 

     itemList.add(myItems); 
     } 

    } catch (JSONException e) { 
       e.printStackTrace(); 
      } 
    } else { 
      Log.e("ServiceHandler", "Couldn't get any data from the url"); 
    } 

return null; 
    } 

    @Override 
    protected void onPostExecute(Void result) { 
     super.onPostExecute(result); 
     // Dismiss the progress dialog 
     if (pDialog.isShowing()) 
      pDialog.dismiss(); 
     /** 
     * Updating parsed JSON data into ListView 
     * */ 
     ListAdapter adapter = new SimpleAdapter(ItemsActivity.this, 
       itemList, R.layout.item_list_item, 
       new String[] { TAG_ITEM_NAME, TAG_UNIT, TAG_TOTAL, TAG_QUANTITY }, 
       new int[] { R.id.itemName, R.id.unit, R.id.total, R.id.quantity}); 

     setListAdapter(adapter); 
    } 

XML :

<TextView 
    android:id="@+id/itemName" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/total" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/unit" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

<TextView 
    android:id="@+id/quantity" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 

지금, 로그에 따라 네 가지가 '가지고'있다, 하지만 내가 ListView에 넣을 때 총 (십진수)은 표시되지 않습니다. 단일 숫자와 기타 10 진수가 완벽하게 표시되며 모든 것이 JSON의 문자열이므로 내 총계를 표시 할 수없는 이유는 무엇입니까? 혼란

...

+2

값을 표시하는 방법을 포함시킬 수 있습니까? 나는 오타가 냄새가 난다. – Marius

+0

@Marius, please 편집 – BlueSkyDevs

+0

@ Marus - 나는 바보 야! 내가 게시 한 코드는 실제 코드가 아니었지만 올바른 영역에있었습니다. XML TextView 중 하나가 R.id.total과 일치하지 않으므로 빠른 변경 후에 완벽하게 표시됩니다. 올바른 방향으로 나를 조종 해 주셔서 감사합니다 !! – BlueSkyDevs

답변

-1

사용이,

findViewById(R.id.itemName).setText(myItems.get(TAG_ITEM_NAME)); 

하지만하기 전에, myItems 접근

.

+1

그는 getView를 오버라이드하지 않고있다. 당신의 대답은 완전히 무의미하다. – Marius

+0

당신이 정확합니까, 그는 활동 컨텍스트를 사용하여 그걸 사용할 수 있습니다. –

+0

은 내가 올바른있어 거의 확신 : 'ListAdapter 어댑터 = 새로운 SimpleAdapter (ItemsActivity.this을 itemList에, R.layout.item_list_item, 새로운 String [] {TAG_ITEM_NAME, TAG_UNIT, TAG_TOTAL, TAG_QUANTITY}, 새로운 int [] {R.id.itemName, R.id.unit, R.id.total, R.id.quantity}); setListAdapter (adapter); ' – Marius

관련 문제