2012-05-10 4 views
0

CursorAdapterカスタムを作成しようとしています。私はDBAdapterクラスにあるデータベースをセットアップしました。私が持っている:CursorAdapterにカーソルを設定する機能がないようです

public class ExampleCursorAdapter extends CursorAdapter { 

    public ExampleCursorAdapter(Context context, Cursor c) { 
     super(context, c); 
    } 

    public void bindView(View view, Context context, Cursor cursor) { 
     TextView summary = (TextView)view.findViewById(R.id.label); 
     summary.setText(cursor.getString(
       cursor.getColumnIndex(DBAdapter.question))); 
    } 

    public View newView(Context context, Cursor cursor, ViewGroup parent) { 
     LayoutInflater inflater = LayoutInflater.from(context); 
     View v = inflater.inflate(R.layout.more_results, parent, false); 
     bindView(v, context, cursor); 
     return v; 
    } 

} 

は私がExampleCursorAdapterのインスタンスを作成しています詳細なフィードバックのクラスを持っています。私が持っている問題は、CursorAdapterを設定するものがないようです。

 public class DetailedFeedback extends ListActivity { 
    public void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 

     Cursor c = db.getAllContacts(); 
    ExampleCursorAdapter adapter = new ExampleCursorAdapter(this, c); 
     setListAdapter(adapter); 

    } 

} 

これが正しい構文であるかどうかはわかりません。

答えて

0

カスタムアダプタのコンストラクタは次のとおりです。

public ExampleCursorAdapter(Context context, Cursor c) { 
    super(context, c); 
} 

、あなたはそれをインスタンス化するときにnullContextnullCursorを設定します。アダプタをインスタンス化するカーソルを設定します。もあります。

+0

返信しようとしている列と同じにする – al23dev

+0

@Alexanderデータベースのクエリ方法を知っていますか? '_id'と' DBAdapter.question'カラムのデータベースに問い合わせを行った後、カーソルを返します。 – Luksprog

+0

カーソルに何を割り当てようとしているのか分かりません。 – al23dev