【问题标题】:Select and display on three edit texts in SQLite在 SQLite 中选择并显示在三个编辑文本上
【发布时间】:2017-07-25 18:53:18
【问题描述】:

有人可以帮我解决我的方法/数据库/查询吗?事情就在这里,我想在我的数据库中传递数据并搜索然后显示。我打算在我的 db 上传递一个唯一键和 3 个 edittext,而 db 是在 edittext 上设置文本的人取决于我的唯一键。

这是我的示例数据库代码(我试过但我知道这是错误的):

我使用以下代码在我的 oncreate 上调用 db(控制器):

Bundle b = new Bundle();
    b = getIntent().getExtras();
    String descpe = b.getString("pedesc");

    context = this;
    controller = new DB_ST(this,"",null,1);

    controller.list_pw_details(descpe, etDesc, etPass, etNote);

数据库方法(查询):

public void list_pw_details(String unqdesc, EditText desc, EditText pass, EditText note){
    Cursor cursor = this.getReadableDatabase().rawQuery("SELECT * FROM PASSWALL WHERE PW_DESC='"+unqdesc+"'", null);
    desc.setText("");
    pass.setText("");
    note.setText("");
    while (cursor.moveToNext()) {
        desc.append(cursor.getString(1));
        pass.append(cursor.getString(2));
        note.append(cursor.getString(3));
    }
}

【问题讨论】:

  • 数据能找回来吗?你不应该通过 EditText..pass String 来代替
  • 当我传递一个文本视图并显示时,我有工作代码。我只尝试传递编辑文本,但不确定它是否有效
  • 贴出开始调用list_pw_details()的代码;
  • 请检查我编辑

标签: android mysql database sqlite methods


【解决方案1】:
public void list_pw_details(String unqdesc, EditText desc, EditText pass, EditText note){

        Cursor cursor = this.getReadableDatabase().rawQuery("SELECT * FROM PASSWALL WHERE PW_DESC='"+unqdesc+"'", null);

        // looping through all rows and adding to list
         while (cursor.moveToNext()) {
                Contact contact = new Contact();  // your object class ,get and set method
                contact.setName((cursor.getString(0));
                contact.setEmail(cursor.getString(1));
                contact.setMobile(cursor.getString(2));
                desc.setText(contact.getName());
                pass.setText(contact.getXXX());
                note.setText(contact.getXXX());
            }
        }
    }

【讨论】:

  • btw 那些是什么 // .... 下面?以及 EditText 通行证和 EditText 注释怎么样 谢谢你
  • 你有包含 set 和 get 方法的 bean 类吗?
  • 我很高兴它有帮助。
猜你喜欢
  • 2012-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 2017-02-03
  • 1970-01-01
相关资源
最近更新 更多