CursorAdapter

来源:互联网 发布:网络英语培训机构排行榜 编辑:程序博客网 时间:2024/05/22 13:09

CursorAdapter

public class MyCursorAdapter extends CursorAdapter{    //必须重写的构造方法    public MyCursorAdapter(Context context,Cursor cursor,int flags){        super(context,cursor,flags);    }    /**    表示创建AdapterView的 item 的view对象    返回适配器控件中每个item对应的view对象    */    public View newView(Context context,Cursor cursor,ViewGroup parent){        View view=LayoutInflater.from(context).inflate(R.layout.activity.other,null);        return view;    }    /**    绑定控件    */    public void bindView(View view,Context context,Cursor cursor){        TextView tv_id=(TextView)view.findViewById(R.id.tv_id);        TextView tv_name=(TextView)view.findViewById(R.id.tv_name);        TextView tv_age=(TextView)view.findViewById(R.id.tv_age);        int id=cursor.getInt(cursor.getColumnIndex("_id"));        String name=cursor.getString(cursor.getColumnIndex("name"));        int age=cursor.getInt(cursor.getColumnIndex("age"));        tv_id.setText(id+"");        tv_name.setText(name);        tv_age.setText(age+"");    }}
0 0