1

私は本当に欲求不満になっています、

解析した 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 }; // 2 EditText fields

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

        // Fill the HashMaps
        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);

私のレイアウト:

<?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">

<ListView 
 android:layout_width="fill_parent" 
 android:layout_height="100dp"
 android:id="@+id/kpn" 
 android:layout_y="350dp">
</ListView> 

<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"
 android:layout_below="@+id/lbl_top"
 android:layout_toRightOf="@+id/editText1">
</EditText>

<RelativeLayout android:id="@+id/LinearLayout01"  
 android:layout_below="@+id/kpn"  
 android:layout_width="fill_parent"  
 android:layout_height="wrap_content"  
 android:layout_alignParentBottom="true"> 

<TextView 
 android:layout_height="wrap_content" 
 android:layout_width="wrap_content" 
 android:text="User Name" 
 android:id="@+id/lbl_username">
</TextView>

<TextView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="Password" 
 android:id="@+id/lbl_password" 
 android:layout_marginLeft="160dp">
</TextView>

<EditText  
 android:id="@+id/txt_username" 
 android:layout_width="120dp" 
 android:layout_height="wrap_content" 
 android:textSize="18sp"
 android:layout_below="@+id/lbl_username">
</EditText> 

<EditText 
 android:layout_height="wrap_content" 
 android:layout_width="120dp" 
 android:id="@+id/txt_password" 
 android:password="true" 
 android:textSize="18sp"
 android:layout_marginLeft="160dp"
 android:layout_below="@+id/lbl_password">
</EditText> 

<Button 
 android:layout_height="wrap_content" 
 android:layout_width="100px" 
 android:id="@+id/btn_login" 
 android:text="Login" 
 android:layout_below="@+id/txt_username">
</Button> 

<Button 
 android:layout_height="wrap_content" 
 android:layout_width="100px" 
 android:id="@+id/cancel_button" 
 android:text="Cancel" 
 android:layout_marginLeft="160dp"
 android:layout_below="@+id/txt_password">
</Button> 

<TextView 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:textSize="14sp"
 android:text="Label result"  
 android:id="@+id/lbl_result"
 android:layout_below="@+id/btn_login">
</TextView> 

<TextView android:lines="6" 
 android:layout_height="20dp" 
 android:layout_width="wrap_content" 
 android:typeface="sans" 
 android:maxLines="12" 
 android:text="Please Loggin First" 
 android:id="@+id/lbl_top" 
 android:textSize="14sp"
 android:layout_below="@+id/lbl_result">
</TextView> 

</RelativeLayout>
</RelativeLayout> 
4

2 に答える 2

1

メインのレイアウトファイルにeditText1とeditText2を含めることはできません。リストビューを使用する場合は、個別のファイルの各行のレイアウトを指定します。そのようです

list_view_row.xml

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout android:orientation="horizontal"
    android:width="fillParent"
    android:height="fillParent"
  />

<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>

次に、次のことを行います。

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

詳細については、このチュートリアルを確認してください。

于 2011-10-21T17:51:22.443 に答える
0

fillMaps-list に正しいデータを設定するのに問題があるようです。行ごとに、新しい HashMap を作成する必要があります (コードでは 1 つだけ作成します)。そして、それを fillMaps に追加します。したがって、HashMap を作成し、その値 ("Col_1" および "Col_2" キーと値) を設定し、そのマップを fillMaps-list に追加する 1 つのループが必要です。fillMaps から LogCat にいくつかの値を記録して、リストに正しく追加されているかどうかを確認してください。

于 2011-10-21T17:47:08.603 に答える