1

アプリでカーソルからリストビューにデータをロードする必要があります。これが私のカスタムアダプタークラスです。そして、それはうまくいきます。しかし、リストビューの最初の行に別のレイアウトを表示する必要があります。リストの最初の行には追加のイメージビューがあります。どうすればそうできますか?私を助けてください。前もって感謝します。

public class CustomSCAdapter extends SimpleCursorAdapter {
Cursor c;
Context context;
Activity activity;
int layout;

public CustomSCAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags ) {
    super(context, layout, c, from, to, flags);
    this.c = c;
    this.context=context;
    this.activity=(Activity) context;
    this.layout = layout;

}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final View view = LayoutInflater.from(context).inflate(this.layout, parent, false);
    return view;
}  

@Override
public void bindView(View view, Context context, Cursor cursor) {
       //here finding all my views in row from view object and binding data from cursor as per my requirement.
     }

}

編集:実際には、フラグメントでローダーメカニズムを使用しているため、アダプタークラスのコンストラクターのカーソル変数に null を渡しています。

    getLoaderManager().initLoader(0, null, this);
    adapter = new CustomSCAdapter(getActivity(), R.layout.row_layout, null, from, to, 0);
4

1 に答える 1

0

最も簡単な方法は、この回答に記載されているように、最初の項目をリストのヘッダーとして扱うことです。

newViewより単純な (しかし醜い) アプローチは、これらの句をandbindViewメソッドに入れることです。

if (cursor.isFirst()) {
 // inflate a different layout containing the imageview or populate the imageview
} else {
 // add logic for other rows here
}
于 2013-06-10T11:39:28.047 に答える