我有一个 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);