search a value from sqlite database and retrieve in listview

前端 未结 3 634
一生所求
一生所求 2020-12-05 22:02

How to find the exact data in sqlite database and retrieve it in a listactivity? I tried like this but I didn\'t get the value.

sea         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-05 22:47

    put below method in your database class:

    public ArrayList getlist(String search) {
    
            ArrayList alTasklist = new ArrayList();
    
            try {
                Cursor mCursor = db.query(true, Contactsnew.TABLE02,
                        new String[] { your field list }, SearchColumnname + "='" + search
                                + "'", null, null, null, null, null);
    
                if (mCursor != null) {
                    mCursor.moveToFirst();
                    for (int i = 0; i < mCursor.getCount(); i++) {
                        alTasklist.add(mCursor.getString(0));
                        mCursor.moveToNext();
                    }
                    mCursor.close();
                    return alTasklist;
                }
                return alTasklist;
            } catch (Exception e) {
                e.printStackTrace();
            }
    
            return alTasklist;
        }
    

    Now get this method in your activity and then Initialize that return arraylist into ListView...

提交回复
热议问题