2017-03-18 65 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