1

我有一个 list_view_row xml 文件。list_view_row.xml 包含editText 框,我想用它们在我的主程序(Android.java)的列表框中显示项目(由SimpleAdapter 收集)。Eclipse 不会让我编译代码,因为我需要在 Android.java 中声明这些 editText 框

 int[] to = new int[] { R.id.editText1, R.id.editText1 };

我怎么做?先感谢您。

list_view_row.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal" 
  android:width="100dp" 
  android:height="100dp"
>

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

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

</LinearLayout>

main.xml 中的代码:

@Override 
    protected void onPostExecute(String result) { 
        //publishProgress(false); 
        // 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("Hashmap: " + map);
            System.out.println(tdFromSecondColumn.text()); 

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

            System.out.println("Hashmap: " + map);
            System.out.println(tdFromSecondColumn1.text());
        }

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

1 回答 1

1

您的 XML 不正确,这是正确的格式:

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

一旦你更正了这个,构建你的项目并且 R.id.editText1 和 R.id.editText2 应该在代码中被识别。

编辑:提示 - 转到顶部的项目菜单,然后转到“自动构建”。这将导致您的项目在保存文件(java / xml)时构建。修改 XML 并保存后,它将构建并使您的 editText1 资源可供 R.id.editText1 访问。

于 2011-10-21T23:55:32.967 回答