내 SQLiteOpenHelper
클래스에 문제가 있습니다. 프린터 제조업체의 데이터베이스와 모든 종류의 프린터에 대한 세부 정보가 있습니다. 나는이 코드로 내 데이터베이스에서 모든 제조업체를 얻고 arraylist로 반환하려고합니다.SQLOpenHelper가 작동하지 않는 ArrayList 가져 오기
// 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;
}
모든 제조업체를 한 번만 목록으로 원합니다. 어쨌든 나는 그것을 작동시키지 못한다. 아직 신참입니다.
도움 주셔서 감사합니다. 또한 SQLite는의 고유 한 키워드 (http://www.sqlite.org/lang_select.html)를 사용할 수 있습니다
// 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
if (!manufacturerList.contains(cursorManufacturer)) {
manufacturerList.add(cursorManufacturer);
} else {
System.out.println("cursorManufacturernot found");
}
}while(cursor.moveToNext());
}
감사합니다 당신이 이것을 설명해주었습니다 :) – Katamave
@Katamave 이것이 도움이된다고 생각한다면 대답을 받아들이는 것을 잊지 마십시오. –
@Katamave : 괜찮습니다. –