2012-05-10 2 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

관련 문제