sqlite db からスピナーを設定できません。誰でも私を助けてもらえますか?
以下は私のコードです
LoginDatabaseAdapter.java
public List<String> GetAllLabels(){
List<String> labels = new ArrayList<String>();
try
{
String selectQuery = "SELECT ID,category FROM CategoryMaster";
SQLiteDatabase db = this.getDatabaseInstance();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
labels.add(cursor.getString(1));
} while (cursor.moveToNext());
}
// closing connection
cursor.close();
}
catch(Exception e)
{
String StackTrace=Log.getStackTraceString(e);
Toast.makeText(context,lineno+StackTrace,Toast.LENGTH_LONG).show();
}
// returning lables
return labels;
}
}
AddProduct.java
private void loadSpinnerData()
{
try
{
LoginDataBaseAdapter db = new LoginDataBaseAdapter(getApplicationContext());
List<String> lables = db.GetAllLabels();
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, lables);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
Spinnercategory.setAdapter(dataAdapter);
}
catch(Exception e)
{
String stackTrace = Log.getStackTraceString(e);
Toast.makeText(getApplicationContext(), stackTrace, Toast.LENGTH_LONG).show();
}
}
よろしくお願いします