java - Android SQLite 如果列等于用户名则列出所有数据 [帮助编写原始查询]

标签 java android sql sqlite android-sqlite

因此,我尝试将用户输入的唯一数据直接关联回他们,我有一个登录名,用于检查 SQLite 中的用户名和密码,如果它匹配启动 Activity Intent ,则将详细信息保存在 SharedPref

从那里,对于用户所做的每一个新注释,它都会在sharedpref中获取他的用户名并将其添加到SQLite

如何查询获取所有笔记?因此,如果 SharedPref 键值用户名等于创建者列,则返回等于键值用户名 == 创建者列的所有数据。

    public void populateList(){
      Cursor cursor = control.listNotes();

      listView = (ListView) getView().findViewById(android.R.id.list);
      NotesAdapter adapter = new NotesAdapter(getActivity(), cursor);

      listView.setAdapter(adapter);

    control.close();
}

public class NotesAdapter extends CursorAdapter {

public NotesAdapter(Context context, Cursor cursor) {
    super(context, cursor, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    return LayoutInflater.from(context).inflate(R.layout.list_layout, parent, false);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {

    TextView title = (TextView) view.findViewById(R.id.item_title);
    TextView body = (TextView) view.findViewById(R.id.item_body);
    TextView date = (TextView) view.findViewById(R.id.item_date);

    String getTitle = cursor.getString(cursor.getColumnIndexOrThrow("title"));
    String getBody = cursor.getString(cursor.getColumnIndexOrThrow("body"));
    String getDate = cursor.getString(cursor.getColumnIndexOrThrow("date"));

    title.setText(getTitle);
    body.setText(getBody);
    date.setText(getDate);
}

}

最佳答案

试试这个

public Cursor listNotes(String user) {
    return db.rawQuery("SELECT * FROM Notes WHERE creator =  '" + user + "'", null);
}

关于java - Android SQLite 如果列等于用户名则列出所有数据 [帮助编写原始查询],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29014855/

相关文章:

java - 在 Netty 4 中迁移 sendUpstream

java - Java 的灵活低级 http 库?

MySQL 在一个查询中对不同表进行多次计数

android - 多媒体音量而不是 Android 中的电话音量

mysql - 如何在多行上执行 datediff

sql - INT或附近的PostgreSQL语法错误

java - 检索 enum int 值

java - 创建没有实例的枚举有什么用?

android - 如何确定 AlertDialog 按钮的最大文本长度?

Android 旋转矩形和理解 Canvas