【问题标题】:Listview relativelayout simpleadapter not workingListview relativelayout simpleadapter不工作
【发布时间】:2011-10-21 14:52:57
【问题描述】:

我正在尝试在位于相对布局中的列表视图中显示一些项目。 整个布局位于一个 xml 文件(main.xml)中

布局还有 2 个按钮和另外 2 个文本字段 (EditText)。

我无法让它工作,因为:

  1. 列表视图不显示项目

  2. 如果列表视图展开,它会复制布局中的按钮和文本字段

有人可以帮帮我吗?

这是布局的一部分:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="@drawable/kpnback">

 <EditText 
  android:layout_height="wrap_content" 
  android:layout_width="110dp" 
  android:id="@+id/editText1"
  android:text="edit1"
  android:inputType="textMultiLine"
  android:layout_below="@+id/lbl_top">
 </EditText> 

 <EditText 
  android:layout_height="wrap_content" 
  android:layout_width="110dp" 
  android:id="@+id/editText2" 
  android:text="edit2"
  android:inputType="textMultiLine"
  android:layout_marginLeft="160dp"
  android:layout_below="@+id/lbl_top">
 </EditText> 

 <ListView 
  android:layout_width="fill_parent" 
  android:layout_height="20dp"
  android:id="@+id/kpn" 
  android:layout_y="350dp"
  android:layout_below="@+id/editText1">
 </ListView> 
</RelativeLayout> 

simpleadapter 的代码:

@Override 
    protected void onPostExecute(String result) { 
        // create the grid item mapping
        ListView kp = (ListView)findViewById(R.id.kpn);

        String[] from = new String[] {"col_1", "col_2"};
        int[] to = new int[] { R.id.editText1, R.id.editText1 };

        List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map = new HashMap<String, String>();

        Document doc = Jsoup.parse(kpn);
        Elements tdsFromSecondColumn = doc.select("table.personaltable td:eq(0)");
        Elements tdsFromSecondColumn1 = doc.select("table.personaltable td:eq(1)"); 

        for (Element tdFromSecondColumn : tdsFromSecondColumn) {
            map.put("col_1", tdFromSecondColumn.text()); 
            fillMaps.add(map);

            System.out.println(tdFromSecondColumn.text()); 

        } 
        for (Element tdFromSecondColumn1 : tdsFromSecondColumn1) {
            map.put("col_2", tdFromSecondColumn1.text());
            fillMaps.add(map);

            System.out.println(tdFromSecondColumn1.text());
        }

        SimpleAdapter adapter = new SimpleAdapter(AndroidLogin.this, fillMaps, R.layout.main, from, to); 
        kp.setAdapter(adapter);

【问题讨论】:

    标签: android listview android-layout android-relativelayout simpleadapter


    【解决方案1】:

    1) 不要使用“@+id/...”作为 layout_below 属性。而是使用“@id/...”

    2) lbl_top 不存在于 RelativeLayout..

    3) 除了指定 layout_below 之外,您还必须指定 layout_toLeftOf 或 layout_toRightOf。

    希望这有帮助..

    【讨论】:

    • 嗨 c05mic,第 1 点:已更正。第 2 点:lbl_top 存在于 relativelayout 中,只是不包含在代码示例中。第3点:你能举一个与我的代码相关的例子吗?我不知道你到底是什么意思。我必须对所有项目都这样做吗?谢谢。
    • 只有相关属性上面有吗..希望这有帮助..
    猜你喜欢
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    • 2013-04-27
    相关资源
    最近更新 更多