在Android中搜索自定义列表视图?

在Android中搜索自定义列表视图?,android,listview,sqlite,Android,Listview,Sqlite,我有一个带有搜索功能的自定义listview,在搜索它时,它会以不同的id显示所有列表?我是否遗漏了什么。有人能找到解决方案吗, 提前谢谢 1.1搜索函数类 sqlCon = new SQLiteConnectornew(this); sqlCon.open(); Cursor cursor = SQLiteConnectornew.fetchAllvalues1(); //cursor.close(); String[] from = new

我有一个带有搜索功能的自定义listview,在搜索它时,它会以不同的id显示所有列表?我是否遗漏了什么。有人能找到解决方案吗, 提前谢谢

1.1搜索函数类

sqlCon = new SQLiteConnectornew(this);
     sqlCon.open();

        Cursor cursor = SQLiteConnectornew.fetchAllvalues1();
        //cursor.close();
    String[] from = new String[] { Contactsnew.TITLE};
    int[] to = new int[] { R.id.title };
    custAdapter = new CustomContactsAdapternew(this,
            R.layout.activity_contactlist, null, from, to);
    setListAdapter(custAdapter);
    search = (EditText) findViewById(R.id.alertsearch);
    search.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            // TODO Auto-generated method stub
            custAdapter.getFilter().filter(s.toString());  
        }

    });
    custAdapter.setFilterQueryProvider(new FilterQueryProvider() {
         public Cursor runQuery(CharSequence constraint) {
             return SQLiteConnectornew.fetchCountriesByName1(constraint.toString());
         }
     });
     listView.setAdapter(custAdapter);
     listView.setTextFilterEnabled(true);
2.db级

public SQLiteConnectornew(Context context) {
    sqlHp = new SQLiteHelpernew(context, Contactsnew.DB_NAME, null, 1);
}

public void insertContact(String title, String category, int _id1) {
    ContentValues cv = new ContentValues();
    cv.put(Contactsnew.TITLE, title);
    cv.put(Contactsnew.CATEGORY, category);
    cv.put(Contactsnew.userId, _id1);

    db = sqlHp.getWritableDatabase();
    db.insert(Contactsnew.TABLE2, null, cv);
    //db.close();

}

public void updateContact(long _id, int _id1, String title,
        String category) {
    ContentValues cv = new ContentValues();
    cv.put(Contactsnew.TITLE, title);
    cv.put(Contactsnew.CATEGORY, category);
    cv.put(Contactsnew.userId, _id1);
    //cv.put(Contactsnew.userid, _id);
    //cv.put(Contactsnew.IMAGE, blob);

    db = sqlHp.getWritableDatabase();
    db.update(Contactsnew.TABLE2, cv, Contactsnew.userid + "=_id" + " AND " + Contactsnew.userId + "=_id1", null);
    //db.update(Contactsnew.TABLE2, cv, Contactsnew.userid + "=_id", null);
    db.update(Contactsnew.TABLE2, cv, Contactsnew.TITLE + "=title", null);
    db.close();
}

public Cursor getAllContacts() {
    db = sqlHp.getReadableDatabase();
    cur = db.query(Contactsnew.TABLE2, null, "_id1=" + GetSet.getUserId(),
            null, null, null, "title");
    return cur;
public static Cursor fetchAllvalues1() {

      Cursor mCursor = db.query(Contactsnew.TABLE2, new String[] {Contactsnew.userid,Contactsnew.userId,Contactsnew.CATEGORY,Contactsnew.TITLE},
        null, null, null, null, null);

      if (mCursor != null) {
       mCursor.moveToFirst();
      }
      return mCursor;
     }
public static Cursor fetchCountriesByName1(String inputText) throws SQLException {
      Log.w(TAG, inputText);
      Cursor mCursor = null;
      if (inputText == null  ||  inputText.length () == 0)  {
       mCursor = db.query(Contactsnew.TABLE2, new String[] {Contactsnew.userid,Contactsnew.userId,Contactsnew.CATEGORY,Contactsnew.TITLE},
         null, null, null, null, null);

      }
      else {
       mCursor = db.query(true, Contactsnew.TABLE2, new String[] {Contactsnew.userid,Contactsnew.userId,Contactsnew.CATEGORY,Contactsnew.TITLE},
         Contactsnew.userId + " AND " +Contactsnew.TITLE + " like '%" + inputText + "%'", null,
         null, null, null, null);
      }
      if (mCursor != null) {
       mCursor.moveToFirst();
      }
      return mCursor;

     }

在你的sqlitedatabase中,我编辑了一些代码,试试这个

public static Cursor fetchAllvalues1() {

      Cursor mCursor = db.query(Contactsnew.TABLE02, new String[] {Contactsnew.userid,Contactsnew.userId,Contactsnew.CATEGORY,Contactsnew.TITLE},
        null, null, null, null, null);

      if (mCursor != null) {
       mCursor.moveToFirst();
      }
      return mCursor;
     }
public static Cursor fetchCountriesByName1(String inputText) throws SQLException {
      Log.w(TAG, inputText);
      Cursor mCursor = null;
      if (inputText == null  ||  inputText.length () == 0)  {
       mCursor = db.query(Contactsnew.TABLE02, new String[] {Contactsnew.userid,Contactsnew.userId,Contactsnew.CATEGORY,Contactsnew.TITLE},
         null, null, null, null, null);

      }
      else {
          mCursor=db.rawQuery(" SELECT * FROM "+ Contactsnew.TABLE02 + " WHERE " 
                    + Contactsnew.userId + " = " + GetSet.getUserId() + " AND " + Contactsnew.TITLE +
                             " LIKE ? " ,new String []{inputText +"%"});
      }
      if (mCursor != null) {
       mCursor.moveToFirst();
      }
      return mCursor;

     }

你的问题到底是什么?如果你使用更多的文本视图,那么它将从所有文本中进行搜索。为此,您必须在适配器类中编写自己的filter()方法。我的问题是它会过滤不同id中存在的所有列表,我只想搜索特定的id列表!!例如:假设我以id:86登录,我将添加一些数据,它将显示为一个列表,同时搜索它,显示其他id中存在的所有内容!!!