我已经实现SyncAdapter
了调用 web 服务和插入/更新数据库。我想显示其中的一些数据,ListView
所以我ListFragment
在女巫中实现了数据通过CursorAdapter
. 一切正常,除了当我从网络获取新数据并将其插入数据库时,CursorAdapter
未更新且新数据未显示在ListView
在我的ContentProvider
, 每次插入后我调用context.getContentResolver().notifyChange(uri, null);
这是ListFragment
实现适配器的一部分
mAdapter = new ObavijestiAdapter(getActivity(), null, 0);
setListAdapter(mAdapter);
这是我的自定义适配器
public class ObavijestiAdapter extends CursorAdapter {
private Cursor mCursor;
private Context mContext;
private final LayoutInflater mInflater;
static class ViewHolder {
public TextView hTextNaslov;
public TextView hTextOpis;
public ImageView hImage;
}
public ObavijestiAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
mInflater = LayoutInflater.from(context);
mContext = context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final ViewHolder holder = (ViewHolder)view.getTag();
//TODO: REMOVE AFTER IMPLEMENTING REAL IMAGE
int w = 24, h = 24;
Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap bmp = Bitmap.createBitmap(w, h, conf); // this creates a MUTABLE bitmap
//END REMOVE
holder.hImage.setImageBitmap(bmp);
holder.hTextNaslov.setText(cursor.getString(cursor.getColumnIndex(DataContract.Obavijesti.OBAVIJESTI_NASLOV)));
holder.hTextOpis.setText(cursor.getString(cursor.getColumnIndex(DataContract.Obavijesti.OBAVIJESTI_OPIS)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view=mInflater.inflate(R.layout.fragment_obavijesti_row,parent,false);
final ViewHolder holder = new ViewHolder();
holder.hTextOpis = (TextView) view.findViewById(R.id.obOpis);
holder.hTextNaslov = (TextView) view.findViewById(R.id.obNaslov);
holder.hImage = (ImageView) view.findViewById(R.id.oblist_image);
view.setTag(holder);
return view;
}
有谁能够帮我?