您好我在这里看到了几个问题,但我没有找到一个真正能帮我解决这个问题的问题...我已经在Android应用程序中实现了一个SQLITE数据库,spinner已经从SQLITE获取了数据,但我有一个问题......当用户在第一个微调器中选择第一个选项时,我需要第二个微调器处于活动状态,因此第二个微调器将根据第一个选择加载内容...例如我有列名为“Modelos”并有2个选项“Modelo1”和“Modelo2”,当用户选择“Modelo1”时将在第二个微调器中显示X信息,当用户选择“Modelo2”时,它将在第二个微调器上显示y信息。 ..这是我的代码:
DBackend -
//Make the selection of the first spinner
public String[] getAllSpinnerContent(){
String query = "Select Modelo from Modelos";
Cursor cursor = this.getDbConnection().rawQuery(query, null);
ArrayList<String> spinnerContent = new ArrayList<String>();
if(cursor.moveToFirst()){
do{
String word = cursor.getString(cursor.getColumnIndexOrThrow("Modelo"));
spinnerContent.add(word);
}while(cursor.moveToNext());
}
cursor.close();
String[] allSpinner = new String[spinnerContent.size()];
allSpinner = spinnerContent.toArray(allSpinner);
return allSpinner;
}
//Make the selection of second spinner
public String[] getAllApelidos () {
String query = "Select Apelido from Modelos";
Cursor cursor = this.getDbConnection().rawQuery(query, null);
ArrayList<String> spinnerApelidos = new ArrayList<String>();
if(cursor.moveToFirst()){
do{
String word = cursor.getString(cursor.getColumnIndexOrThrow("Apelido"));
spinnerApelidos.add(word);
} while (cursor.moveToNext());
}
cursor.close();
String[] allApelidos = new String[spinnerApelidos.size()];
allApelidos = spinnerApelidos.toArray(allApelidos);
return allApelidos;
}
}
这是我的活动,展示了2个微调器
package com.rafa.rafa_v2;
import android.content.Context;
import android.database.Cursor;
import java.util.ArrayList;
/**
* Created by rafaelabueno on 01/03/16.
*/
public class DbBackend extends DbObject{
public DbBackend(Context context) {
super(context);
}
//Pega o Modelo
public String[] getAllSpinnerContent(){
String query = "Select Modelo from Modelos";
Cursor cursor = this.getDbConnection().rawQuery(query, null);
ArrayList<String> spinnerContent = new ArrayList<String>();
if(cursor.moveToFirst()){
do{
String word = cursor.getString(cursor.getColumnIndexOrThrow("Modelo"));
spinnerContent.add(word);
}while(cursor.moveToNext());
}
cursor.close();
String[] allSpinner = new String[spinnerContent.size()];
allSpinner = spinnerContent.toArray(allSpinner);
return allSpinner;
}
//Pega o Apelido
public String[] getAllApelidos () {
String query = "Select Apelido from Modelos";
Cursor cursor = this.getDbConnection().rawQuery(query, null);
ArrayList<String> spinnerApelidos = new ArrayList<String>();
if(cursor.moveToFirst()){
do{
String word = cursor.getString(cursor.getColumnIndexOrThrow("Apelido"));
spinnerApelidos.add(word);
} while (cursor.moveToNext());
}
cursor.close();
String[] allApelidos = new String[spinnerApelidos.size()];
allApelidos = spinnerApelidos.toArray(allApelidos);
return allApelidos;
}
}
如果有人可以帮助我,我真的很高兴!