0

我正在尝试在位于相对布局中的列表视图中显示一些项目。整个布局位于一个 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> 

简单适配器的代码:

@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);
4

1 回答 1

0

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

2)lbl_top 不存在于 RelativeLayout..

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

希望这可以帮助..

于 2011-10-21T15:10:38.450 回答