3

私はAndroidの初心者です。レイアウトでハードコーディングするのではなく、manin スレッドで指定する必要があるカスタム情報が 1 行にある、拡張可能な ListView を作成したいと考えています。

画像と2つのテキストビューが必要です。カスタム レイアウト ファイルが必要になると思いますが、コード内でそれを呼び出す場所がわかりません。手伝ってください。

以下は、カスタム アダプター内の GropView fxn です。ケース 0 でカスタム レイアウト ファイルを読み込みたい

public View getGroupView(int groupPosition, boolean arg1, View convertView,
        ViewGroup arg3) {

    String laptopName = (String) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.group_item, null);
    }
    TextView item = (TextView) convertView.findViewById(R.id.laptop);
    item.setTypeface(null, Typeface.BOLD);
    item.setText(laptopName);

    this.context = (Activity) context;
    switch (groupPosition) {
    case 0:
        convertView.setBackgroundColor(this.context.getResources()
                .getColor(R.color.dark_blue));
        convertView.inflate(R.layout.first_row_layout, 0, arg3);
        break;
    case 1:
        convertView.setBackgroundColor(this.context.getResources()
                .getColor(R.color.purple));
        break;
    case 2:
        convertView.setBackgroundColor(this.context.getResources()
                .getColor(R.color.green));
        break;
    default:
        break;
    }

    return convertView;
}
4

1 に答える 1

1

グループ項目のレイアウトを定義するコード内の位置は次のとおりです。

 if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.group_item, null);
    }

あなたの場合、グループ項目にレイアウト R.layout.group_item を使用しています。グループの位置ごとに異なるレイアウトをロードしたい場合は、コードのこの部分を switch-case 内に移動する必要があります。ListView 内の画像には注意する必要があります。詳細については、次を参照してください。

http://developer.android.com/training/improving-layouts/smooth-scrolling.html

于 2013-08-03T21:19:21.407 に答える