SQLiteOpenHelper
クラスに問題があります。プリンターの製造元とあらゆる種類のプリンターの詳細を含むデータベースがあります。このコードを使用して、データベースからすべてのメーカーを取得し、それらを配列リストに戻そうとします。
// Read database for All printer manufacturers and return a list
public ArrayList<String> getPrManufacturer(){
ArrayList<String> manufacturerList = new ArrayList<String>();
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(CoDeskContract.Printer.TABLE_NAME,
printerManuProjection, null, null, null, null, null,null);
// If cursor is not null and manufacturer List
// does not contains Manufacturer in the list then add it!
if ((cursor != null) && (cursor.getCount()>0)){
cursor.moveToFirst();
do {
String cursorManufacturer = cursor.getString(0);
//Checking for manufacturer in the list
for(String manufacturerInList:manufacturerList){
if (!manufacturerInList.equals(cursorManufacturer))
manufacturerList.add(cursorManufacturer);
}
}while(cursor.moveToNext());
}
// Return list of manufacturers from database
return manufacturerList;
}
私はすべてのメーカーをリストに一度入れたいと思っています。どういうわけか私はそれを機能させることができません。私はまだ初心者です。
助けてくれてありがとう。