나는 SimpleCursorAdapter
을 사용하여 데이터베이스에 대한 내 쿼리를 관리 한 다음 결과를 ListView
에 표시합니다.Android SimpleCursorAdapter to CursorAdapter
database.open();
ListView listContent = (ListView)findViewById(android.R.id.list);
Cursor c = database.getData();
startManagingCursor(c);
String[] from = new String[]{Database._GROUP_NAME};
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, query, from, to);
listContent.setAdapter(adapter);
database.close();
예상대로 첫번째보기에, 그것은 작업의 IT,하지만, 나는이 CursorAdapter
있기 때문에 진행하는 방법이되어서는 안된다는 생각 :
여기 내 코드입니다.
나는 이것이 멍청한 질문이라는 것을 알고 있지만, 이제 Android에서 프로그래밍을 시작한 이래로 나는 아직도 많이 알지 못합니다.
SimpleCursorAdapter
에서 CursorAdapter
으로 어떻게 전달할 수 있습니까? 이미 인터넷에서 검색되었지만이를 수행하는 방법을 이해할 수 없었습니다.
방향을 묻지 않고 코드를 묻습니다. mainu의 COMMENT 파악하기
감사
favolas
UPDATE
database.open();
ListView listContent = (ListView)findViewById(android.R.id.list);
Cursor c = database.getData();
MyAdapt cursorAdapter = new MyAdapt(this, query);
listContent.setAdapter(adapter);
database.close();
MyAdapt 클래스 :
public class MyAdapt extends CursorAdapter {
private final LayoutInflater mInflater;
public MyAdapt(Context context, Cursor c) {
super(context, c);
mInflater = LayoutInflater.from(context);
mContext = context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView groupName = (TextView) view.findViewById(android.R.id.text1);
groupName.setText(cursor.getString(cursor
.getColumnIndex(Database._GROUP_NAME)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = mInflater.inflate(
android.R.layout.simple_list_item_1, parent, false);
return view;
}
}
이 올바른 방법이 있나요?
SimpleCursorAdapter 클래스를 만들어 CursorAdapter를 확장합니다. 그리고 당신은 기본적으로 지나치게 많은 방법을 얻을 것입니다. UU는 다음을 지울 것입니다 – mainu
@ 메인 감사합니다. 내 업데이트를 참조하십시오. – Favolas