因此,我尝试将用户输入的唯一数据直接关联回他们,我有一个登录名,用于检查 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/