0

次の形式のカスタム リストビューを作成したいと考えています。例えば

 _______________________________________
|                                       |
| -----------           ------------    |
|  Principal              EditView      |
| -----------           ------------    |
|                                       |
| -----------           ------------    |
|  Years                  EditView      |
| -----------           ------------    |
|                                       |
| -----------           ------------    |
|  Rate of Int             EditView     |
| -----------           ------------    |
|_______________________________________|

 _______________________________________
|                                       |
| -----------           ------------    |
|  Interest               EditView      |
| -----------           ------------    |
|_______________________________________|

 _______________________________________
|                                       |
| -----------           ------------    |
|  Simple Int             EditView      |
| -----------           ------------    |
|_______________________________________|

 _______________________________________
|                                       |
| ------------          ------------    |
|  Compond Int            EditView      |
| ------------          ------------    |
|_______________________________________|

つまり、リストビューのitem1には3つのテキストと編集ビューが含まれ、item2には2つのテキストと編集ビューが含まれている必要があります。両方の項目が異なる入力を取得する必要があります。

私はAndroidが初めてなので、簡単なリストビューを作成できましたが、さまざまなビューでリストビューを作成する方法がわかりません。

4

3 に答える 3

1

カスタム アダプターを作成する必要があります。このアダプターは、セルごとに独自の xml ビューを拡張できます。

新しいxmlビューは、リストビューが使用する最も複雑なレイアウトを単純に持つ必要があり、サブビューの情報を使用しない各セルに対して、そのサブビューを非表示に設定するだけです.

これは少なくとも正しい方向にあなたを導くはずです

于 2012-08-08T20:16:48.313 に答える
0

独自の ArrayAdapter を作成することはうまくいきました。そこでメソッドを取得します

上書きできる getView() 。

そこで LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); を使用します。レイアウトで XML として定義した独自のビューを膨らませます。このメソッドで直接ビュー要素を埋めることができます。

私のコードでは、アイコン、2 つのテキスト フィールド、および ProgressBar のレイアウトを作成しました。次のようになります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 ... >

    <ImageView
        android:id="@+id/inventory_item_icon"
        .../>

    <TextView
        android:id="@+id/inventory_item_titel"
        .../>


    <TextView
        android:id="@+id/inventory_status_textfield"
        ... />

    <TextView
        android:id="@+id/inventory_item_info"
        ... />

    <ProgressBar
        android:id="@+id/inventory_item_status"
        ... />

</RelativeLayout>

getView() に直接入力するのが簡単だった後、私のコードは次のようになります。

public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.inventory_icon_text_text, parent, false);
TextView textViewTitel = (TextView) rowView.findViewById(R.id.inventory_item_titel);
TextView textViewInfo = (TextView) rowView.findViewById(R.id.inventory_item_info);
ImageView imageView = (ImageView) rowView.findViewById(R.id.inventory_item_icon);

textViewTitel.setText(values[position]);
  String s = values[position];
    if (s.equals("A")) {
       imageView.setImageResource(R.drawable.a);
       textViewInfo.setText("This is case A!"); 
    } else if (s.equals("B")) {
    return rowView;
}

したがって、個々の View 要素に直接対処できます。異なるビュー レイアウトが必要な場合は、レイアウトを拡張する前にこれを確認してみてください。使いたいものを選んでいただきありがとうございます。

これがお役に立てば幸いです!トバイアス

于 2012-08-08T20:38:15.810 に答える