[英]Android SQLite show specific row on spinner selected
我從 3 個難度中獲得了創紀錄的高分:簡單、中等、困難。 所有數據進入 1 個表。 我有 1 個活動來顯示所有的高分。
在那個活動中,我創建了一個微調器,讓用戶選擇他們想要顯示的難度數據。 所有數據都將顯示在列表視圖(ScoreView)中。
這里我想做的是在微調器上選擇用戶時顯示特定數據。
有什么辦法嗎?
這是我的數據庫:
public Data_Collect[] getScore() {
Data_Collect[] data = null;
String[] colums = {"Difficult", "BRedo", "BCorrect"};
String orderBy = "Difficult ASC";
Cursor cursor = getReadableDatabase().query(
"score",
colums,
null, null, null, null,
orderBy);
if (cursor.getCount()>0 && cursor.moveToNext()) {
data = new Data_Collect[cursor.getCount()];
int counter = 0;
do {
data[counter] = new Data_Collect(
cursor.getString(0),
cursor.getInt(1),
cursor.getInt(2));
counter++;
}
while (cursor.moveToNext());
}
cursor.close();
return data;
}
這是我的活動:
ArrayAdapter<String> adapterDifficult = new ArrayAdapter<>(
Score.this, android.R.layout.simple_list_item_1, Difficulty
);
SpinnerDifficulty.setAdapter(adapterDifficult);
SpinnerDifficulty.setOnItemSelectedListener(this);
new Thread(new Runnable() {
@Override
public void run() {
RecordDB db = new RecordDB(Score.this);
Data_Collect[] data = db.getScore();
db.close();
if (data != null) {
adapter = new RecordAdapter(Score.this, R.layout.recordlist, R.id.text_Difficulty, data);
runOnUiThread(new Runnable() {
@Override
public void run() {
ScoreView.setAdapter(adapter);
}
});
}
}
}).start();
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
定義困難 = '簡單'
Data_Collect[] data = null;
String[] colums = {"Difficult", "BRedo", "BCorrect"};
String orderBy = "Difficult ASC";
Cursor cursor = getReadableDatabase().query(
"score",
colums,
"Difficult ='Easy'", null, null, null,
orderBy);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.