SQLite的回收站视图中不会重新获取数据

时间:2015-11-20 03:30:34

标签: android sqlite

只有部分数据显示在我的RecyclerView中,并且显示的数据不会按顺序显示。此外,RecyclerView中的信息会在滚动时自动更改。

这是我的DatabaseHandler.java

 @Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_CONTACTS_TABLE = "CREATE TABLE "
            + TABLE_CONTACTS + "("
            + KEY_DATE + " TEXT,"
            + KEY_MOBILE_NO + " TEXT,"
            + KEY_HOSPITAL_NAME + " TEXT,"
            + KEY_DIAGNOSIS + " TEXT,"
            + KEY_TREATMENT + " TEXT,"
            + KEY_MEDICINE1 + " TEXT DEFAULT NULL,"
            + KEY_MEDICINE2 + " TEXT DEFAULT NULL,"
            + KEY_MEDICINE3 + " TEXT DEFAULT NULL,"
            + KEY_MEDICINE4 + " TEXT DEFAULT NULL,"
            + KEY_MEDICINE5 + " TEXT DEFAULT NULL,"
            + KEY_MEDICINE6 + " TEXT DEFAULT NULL"
            + ");";
    db.execSQL(CREATE_CONTACTS_TABLE);

}

//存储sqlite数据

  public List<UserInfo> getAllData() {
    List<UserInfo> list = new ArrayList<>();
    String selectQuery = "SELECT  * FROM " + TABLE_CONTACTS;

    SQLiteDatabase db=this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    UserInfo bean = null;
    cursor.moveToFirst();
    while (cursor.moveToNext()) {
        int index0 = cursor.getColumnIndex(KEY_DATE);
        int index1 = cursor.getColumnIndex(KEY_MOBILE_NO);
        int index2 = cursor.getColumnIndex(KEY_DIAGNOSIS);

        String date = cursor.getString(index0);
        String mobile_no = cursor.getString(index1);
        String heading = cursor.getString(index2);
        bean = new UserInfo(date,mobile_no,heading);
        list.add(bean);
    }



    return list;


}

这是我的fragment.class

public class My_Health extends Fragment {

DatabaseHandler db;
public String mobile_no;

protected RecyclerView mRecyclerView;


@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.home, container, false);

    db= new DatabaseHandler(getActivity());
     mobile_no = this.getArguments().getString("MOBILE_NO");



    mRecyclerView = (RecyclerView) v.findViewById(R.id.cardlist_home);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mRecyclerView.setAdapter(new HomeCardAdapter(db.getAllData(), R.layout.cardview_home));

    Log.d("mylog", db.getAllData().toString());




    FloatingActionButton fab = (FloatingActionButton) v.findViewById(R.id.addrecordfab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), AddRecord.class);
            intent.putExtra("MOBILE_NO",mobile_no);
            startActivity(intent);
        }
    });
    return v;
}

}

log

的结果
11-20 11:16:47.689 31511-31511/com.rashim12000.waytofreedom.swasthyatipot D/mylog: [com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@3a6b1a1, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@1b9edfc6, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@3f7cb87, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@21eefab4, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@1e5bc6dd, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@f993252, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@efb9923, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@1ddb0e20, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@152f3d9, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@974219e, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@6e4a47f, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@12b2ec4c, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@8f5f495, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@17cb9aa, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@2629099b, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@9488138, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@348e4511, com.rashim12000.waytofreedom.swasthyatipot.Adapter.UserInfo@35c4c676]

0 个答案:

没有答案