2017-03-18 29 views
0

我有一個列表視圖,它是從PHP中獲得的,它從MySql中獲取它。然而,當一個retice與我形成的簡單的adater不匹配的數據。這裏是我的代碼:ListView確實適應簡單的適配器格式

''HashMap map = new HashMap();

   map.put(TAG_VALOR, valorIntent); 
       map.put(TAG_COMIDA , Scomida); 
       map.put(TAG_TABACO , Stabaco); 
       map.put(TAG_BEBIDAS , Sbebidas); 
       map.put(TAG_SABADO , Ssabado); 
       map.put(TAG_DOMINGO , Sdomingo); 
       map.put(TAG_HIGIROUP , Shigiroup); 
       map.put(TAG_MULTIBANCO , Smultibanco); 
       map.put(TAG_OUTROS , Soutros); 


       productsList.add(map); 
      } 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

     return null; 
    } 



    protected void onPostExecute(String file_url) { 
     // dismiss the dialog after getting all products 
     pDialog.dismiss(); 
     // updating UI from Background Thread 
     runOnUiThread(new Runnable() { 
      public void run() { 



       ListAdapter adapter = new SimpleAdapter(
         Relatorio.this, productsList, 
         R.layout.relatorio_details, new String[] { TAG_COMIDA,TAG_TABACO,TAG_BEBIDAS,TAG_SABADO 
         ,TAG_DOMINGO,TAG_HIGIROUP, TAG_MULTIBANCO, TAG_OUTROS}, 
         new int[] { R.id.comidaRel, R.id.tabacoRel,R.id.bebidasRel, R.id.sabadoRel 
           , R.id.domingoRel, R.id.higroupasRel, R.id.multibancoRel, R.id.outrosRel}); 
       setListAdapter(adapter); 


       Log.d("Multibanco", TAG_MULTIBANCO); 
      } 
     });' 

,這是包裹在的LinearLayout的relatorio_details垂直:

'<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="Comida"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:id="@+id/comidaRel"/> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Tabaco"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/tabacoRel"/> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Multibanco"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/multibancoRel" 
     android:text="0.00"/> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Bebidas"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/bebidasRel" 
     android:text="0.00"/> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Sábado"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/sabadoRel" 
     android:text="0.00"/> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Domingo"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/domingoRel" 
     android:text="0.00"/> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Higiene e Roupas"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/higroupasRel" 
     android:text="0.00"/> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:layout_weight="1" 
    android:id="@+id/outros_rel"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Outros"/> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:id="@+id/outrosRel" 
     android:text="0.00"/> 

</LinearLayout> 

數據顯示,但不尊重relatorio_details佈局

+0

其特定的數據被放置小姐? – rafsanahmad007

回答

0

你需要做一個自定義的適配器類的列表視圖然後,您需要設置列表視圖的適配器 ListView.setAdapter(new CustomAdapter(datalist)); 使用此鏈接以獲得更多幫助 Custom Adapter for List View