这是一个片段。我想从数据库中获取特定数据并将其存储在字符串中,然后将其放入 textview 但我不知道如何构造该方法以及如何使用该方法来获取数据。(光标)请帮帮我。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layoutView = inflater.inflate(R.layout.fragment_lyrics,
container, false);
int hymnNo = fragVal - 1;
//Database
DataBaseHelper myDbHelper = new DataBaseHelper(getActivity());
String lyrics = myDbHelper.data(hymnNo);
View tv = layoutView.findViewById(R.id.text);
//((TextView) tv).setText("Hymn Nunmber " + hymnNo);
return layoutView;
}
这是数据库助手类 DataBaseHelper.java
public Cursor data(int x){
SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH,null,
SQLiteDatabase.OPEN_READONLY);
Cursor c = db.rawQuery("Select Lyrics from Hymns where id = " + x , null);
db.close();
return c;
}