我知道數據被插入到數據庫中,並且它已正確列出,但notifydatasetchanges不起作用,列表視圖不會刷新,所以我必須重新啓動我的活動....notifyDataSetChanged不會被觸發,即使我調用了兩次
Cursor c = db.selectAll();
final ListView lv = (ListView) findViewById(R.id.listView1);
adapter=new MyContactsAdapter(this, c);
lv.setAdapter(adapter);
db.insertInTable("asd","asd");
//insertion in table works, I am sure, cause when I start the activity the new values are listed
//this the part that doesn't works
((MyContactsAdapter)lll.getAdapter()).notifyDataSetChanged();
adapter.notifyDataSetChanged();
lll.refreshDrawableState();
private class MyContactsAdapter extends CursorAdapter{
private Cursor mCursor;
private Context mContext;
private final LayoutInflater mInflater;
public MyContactsAdapter(Context context, Cursor cursor) {
super(context, cursor, true);
mInflater = LayoutInflater.from(context);
mContext = context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView t = (TextView) view.findViewById(R.id.textView2);
t.setText(cursor.getString(0));
t = (TextView) view.findViewById(R.id.TextView01);
t.setText(cursor.getString(1));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = mInflater.inflate(R.layout.item, parent, false);
return view;
}
}//adapter
什麼是同 – Lukap