SimpleCursorAdapter를 사용하는 대신 사용자 고유의 CursorAdapter를 구현하는 것이 좋습니다.
CursorAdapter를 구현하는 것은 다른 어댑터를 구현하는 것보다 어렵지 않습니다. CursorAdapter는 BaseAdapter를 확장하며 getItem(), getItemId() 메서드는 이미 재정의되어 실제 값을 반환합니다. pre-Honeycomb을 지원하는 경우 지원 라이브러리 (android.support.v4.widget.CursorAdapter)의 CursorAdapter를 사용하는 것이 좋습니다. 11 세 이후 인 경우에만 android.widget.CursorAdapter를 사용하십시오. swapCursor (newCursor)를 호출 할 때 notifyDataSetChanged()를 호출 할 필요가 없다는 사실을 염두에 두십시오.
import android.widget.CursorAdapter;
public final class CustomAdapter
extends CursorAdapter
{
public CustomAdapter(Context context)
{
super(context, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
}
// here is where you bind the data for the view returned in newView()
@Override
public void bindView(View view, Context arg1, Cursor c)
{
//just get the data directly from the cursor to your Views.
final TextView address = (TextView) view
.findViewById(R.id.list_item_address);
final TextView title = (TextView) view
.findViewById(R.id.list_item_title);
final String name = c.getString(c.getColumnIndex("name"));
final String addressValue = c.getString(c.getColumnIndex("address"));
title.setText(name);
address.setText(addressValue);
}
// here is where you create a new view
@Override
public View newView(Context arg0, Cursor arg1, ViewGroup arg2)
{
return inflater.inflate(R.layout.list_item, null);
}
}
SimpleCursorAdapter를 사용하는 대신 사용자 고유의 CursorAdapter를 구현하는 것이 좋습니다. –
Thanks @DctororDrive, 귀하의 의견은 좋은 것입니다. 마술처럼 대답으로 바꾸는 것을 고려해 볼 수 있습니다. 커스텀'CursorAdapter'를 만드는 방법을 간략하게 설명하는 시간이 필요하다면 저에게 적어도 25 포인트를 이길 수 있습니다. – SteeveDroz