パターンを使用せずにカスタム CursorAdapter を Android に実装しましたfrom to
。アダプタを広く再利用できるようにするために、アダプタに追加したいと思います。どうすればよいですか?
これは私のアダプターです:
public class AtomAdapter extends CursorAdapter {
LayoutInflater inflater;
@SuppressWarnings("deprecation")
public AtomAdapter(Context context, Cursor c) {
super(context, c);
inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
//will create a new View only when recycling an older View is not possible
View v= inflater.inflate(R.layout.layout_row, parent,false);
TextView tv=(TextView)v.findViewById(R.id.txt_title);
v.setTag(R.id.txt_title,tv);
TextView tv2=(TextView)v.findViewById(R.id.txt_content);
v.setTag(R.id.txt_content,tv2);
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// bind data to your row
TextView txt_title=(TextView)view.getTag(R.id.txt_title);
TextView txt_content=(TextView)view.getTag(R.id.txt_content);
txt_title.setText(cursor.getString(cursor.getColumnIndex(AtomDB.TITLE)));
txt_content.setText(cursor.getString(cursor.getColumnIndex(AtomDB.CONTENT)));
}
}