[cp]从数据库user表中搜索,显示到listview中,点击列表项可以有列表框弹出来,有三个按钮,分别是添加,查看他的信息和查看我的好友,点击添加好友后toast提示已经添加,查看我的好友可以将数据库myfriend(我的好友)表的内容显示到listview中,要求是这样的,用sqlite,
然后应该是,一个表两个类吗,还有一个主类,就是一共是5个类吗?如果可以的话,能给我看看实现代码吗?
如果有差不多源码的就更好啦

解决方案 »

  1.   

    不是,是在edittext里输入,然后sqlite从已有的数据库表搜索显示在listview,点击列表项会有一个弹出框,有三个按钮,分别跳转到不同activity,
    但是代码调试没成功
      

  2.   

    不是,是在edittext里输入,然后sqlite从已有的数据库表搜索显示在listview,点击列表项会有一个弹出框,有三个按钮,分别跳转到不同activity,
    但是代码调试没成功
    哦哦,那没什么了,主要就是sqlite的增删改查,你找个博客看一下怎么用就可以了啊
      

  3.   

    不是,是在edittext里输入,然后sqlite从已有的数据库表搜索显示在listview,点击列表项会有一个弹出框,有三个按钮,分别跳转到不同activity,
    但是代码调试没成功
    哦哦,那没什么了,主要就是sqlite的增删改查,你找个博客看一下怎么用就可以了啊
    不知道是不是查询语句有问题,
      

  4.   

    sqlite获取edittext关键字查询显示在listview
    ,怎么获取到关键字呢?放在listview里需要用到arraylist吗?
      

  5.   

    public class MainActivity extends AppCompatActivity {EditText input;Button send;ListView show;SQLiteDatabase db;PopupMenu popop=null;    @Override    protected void onCreate(Bundle savedInstanceState) {        db = SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString() + "/user.db3", null);        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //获取组件        input = findViewById(R.id.input);        show = findViewById(R.id.show);        send = findViewById(R.id.button);        //搜索按钮被点击从user表中搜索合适的数据        send.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {            }            private void queryRecords(String tempName) {                //模糊搜索                Cursor c = db.rawQuery(                        "select id as _id,name from records where name like '%" + tempName + "%' order by id desc ", null);                // 创建adapter适配器对象,装入模糊搜索的结果                SimpleCu
      

  6.   

    public class MainActivity extends AppCompatActivity {
    EditText input;Button send;ListView show;
    SQLiteDatabase db;
    PopupMenu popop=null;    
    @Override    
    protected void onCreate(Bundle savedInstanceState) {        
    db = SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString() + "/user.db3", null);        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        //获取组件        input = findViewById(R.id.input);       
     show = findViewById(R.id.show);        
    send = findViewById(R.id.button);        
    //搜索按钮被点击从user表中搜索合适的数据        send.setOnClickListener(new View.OnClickListener() {            
    @Override           
     public void onClick(View v) {   
             }            
    private void queryRecords(String tempName) {               
     //模糊搜索                
    Cursor c = db.rawQuery(                       
     "select id as _id,name from records where name like '%" + tempName + "%' order by id desc ", null);       
             // 创建adapter适配器对象,装入模糊搜索的结果                SimpleCursorAdapter adapter = new SimpleCursorAdapter(MainActivity.this,R.layout.activity_main, c, new String[]{"name"},                 
           new int[]{android.R.id.text1}, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);      
              show.setAdapter(adapter);                adapter.notifyDataSetChanged();        
        }       
       /*            
    //搜索好友          
    String titile = input.getText().toString();         
       Cursor c = db.rawQuery("select * from user where  name like ?"    , new String[]{"&" + titile + "&", "&" + titile + "&"});    
            Bundle data = new Bundle(); 
               public Bundle getData() {                
    data.putSerializable("data", converCursorToList(c));                return data;   
             }            
    //显示到列表框           
     protected ArrayList<Map<String, String>>            converCursorToList(Cursor c) {                
    ArrayList<Map<String, String>> result = new ArrayList<Map<String, String>>();                
    while                        
    (c.moveToNext()) {                    
    Map<String, String> map = new HashMap<>();                    map.put("name", c.getString(1));                    result.add(map);                    
    List<Map<String, String>> list = (List<Map<String, String>>)                           
     data.getSerializable("data");                    SimpleCursorAdapter adapter = new SimpleCursorAdapter(MainActivity.this, R.layout.activity_main, c,                            new String[]{"id", "name"}, new int[]{R.id.show},                            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);                    
    show.setAdapter(adapter);             
       }                
    return result;           
     }*/       
     });    
    }}
      

  7.   

    1.获取输入框关键字:input.getText().toString()
    2.你的模糊查询语句好像不太对吧。。我一般都是使用的GreenDao,所以我也不太会写语句,你最好去查一下。
    3.遍历Cursor,将结果封装成一个对象,创建一个List集合保存这些对象即可。
      

  8.   

    seach.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String title = input.getText().toString();
            Cursor cursor = dbhelp.getReadableDatabase().rawQuery("select * from user where name like ? or phone like ?"
                    + new String[]{"%" + title + "%","%"+title+"%"},null);        //创建一个List集合
            result = new ArrayList<Map<String, String>>();
            Map<String, String> map = new HashMap<>();
            map.put("name", cursor.getString(1));
            map.put("phone", cursor.getString(2));
            result.add(map);
            cursor.moveToNext();        //创建一个SimpleAdapter
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(MainActivity.this, R.layout.list_item, cursor, new String[]{"name", "phone"}
                    , new int[]{R.id.show});
            //填充listview
            show.setAdapter(adapter);
    }});
      

  9.   

    你能帮我看一下吗?麻烦你了
    是查询语句有问题吗?  public List<Person> query(String content){
            List<Person> personList = new ArrayList<Person>();        SQLiteDatabase db = personDBOpenHelper.getReadableDatabase();
            Cursor c = db.query("person",
                    new String[]{"id","username","password"},
                    "username LIKE ?  or password LIKE ? ",
                    new String[]{"%" + content + "%" ,"%" + content + "%" },null,null,null);        while(c.moveToNext()){
                int id = c.getInt(c.getColumnIndex("id"));
                String username = c.getString(c.getColumnIndex("username"));
                String password = c.getString(c.getColumnIndex("password"));
                Person person = new Person(id,username,password);
                personList.add(person);
            }        c.close();
            db.close();        return personList;
        }
      

  10.   

    password字段替换成phone就行了
      

  11.   

    不好意思,我不大懂得怎么安进去,
    可以直接在原先的代码上改吗?username、password、id 都是表的字段名(姓名、密码、序号)。我建的表是这几个字段,你根据你建的表来改下这几个就行了。你那个不是phone吗,就直接改成phone就行了。。这个代码我试过了,没问题的。