Listview relativelayout simpleadapter不工作

时间:2011-10-21 14:52:58

标签: android listview android-layout relativelayout simpleadapter

我正在尝试在listview中显示一些项目,它位于relativelayout中。 整个布局位于一个xml文件(main.xml)

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

我无法让它工作,如:

  1. 列表视图不显示项目

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

  3. 有人可以帮帮我吗?

    以下是布局的一部分:

    <?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);
    

1 个答案:

答案 0 :(得分:0)

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

2)在RelativeLayout ..

中不存在lbl_top

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

希望这会有所帮助..