ListView确实适应简单的适配器格式

时间:2017-03-18 08:21:30

标签: java android

我有一个列表视图,它是从一个从MySql中获取它的php重新获得的。但是,当我将数据与我形成的简单adater不匹配时。这是我的代码:

'' 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 vertical中的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布局

1 个答案:

答案 0 :(得分:0)

您需要为列表视图创建自定义适配器类,并且需要设置列表视图的适配器之后的自定义布局是一个简单的xml布局文件 ListView.setAdapter(new CustomAdapter(datalist)); 使用此链接获取更多帮助 Custom Adapter for List View