sqlite로 db불러와서 스피너 1에는 중복값없이 불러오는거 성공했는데
스피너 1값에 대한 스피너 2값을 못불러오네요 ㅠㅠㅠㅠ 대체 어떻게 고쳐야 좋을ㄲㅏ요..
또 이렇게 해도 출발과,선택 값에 따른 요금정보도 또 뿌려줘야하는데ㅣ...아 돌겠습니다 ㅠㅠㅠ 분명 잘못한거면 에러가 나야하는데
에러는 또 왜나는걸까요 ㅠㅠㅠ
public class secondmain1_1_1 extends Activity {
private static String DB_PATH = "/sdcard/";
private static String DB_NAME = "tol.sqlite";
private int listcount = 0;
private String[] startList = null;
private String[] endList = null;
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database does't exist yet.
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
private void copyDataBase() throws IOException{
InputStream myInput = this.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int total_length = 0;
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
total_length+=length;
}
total_length+=length;
myOutput.flush();
myOutput.close();
myInput.close();
}
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
if(dbExist){
//NOTHING
}else{
try {
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.secondmain1_1_1);
try {
createDataBase();
} catch (IOException ioe) {
Toast.makeText(this, "DB 파일을 생성할 수 없습니다.", Toast.LENGTH_LONG).show();
}
listcount = 0;
try {
Cursor cursor;
SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH+DB_NAME, null, 1);
String[] FROM = { "*" };
cursor = db.query(true, "tol", FROM, null, null, "start", null,null, null);
startManagingCursor(cursor);
startList = new String[cursor.getCount()];
//endList = new String[cursor.getCount()];
while(cursor.moveToNext())
{
String start = cursor.getString(0);
//String end = cursor.getString(1);
startList[listcount] = start;
//endList[listcount] = end;
listcount++;
}
if(db != null)
db.close();
} catch (Exception e) {
Toast.makeText(this, "ERROR IN CODE:"+e.toString(), Toast.LENGTH_LONG).show();
}
try {
Cursor cursor;
SQLiteDatabase db = SQLiteDatabase.openDatabase(DB_PATH+DB_NAME, null, 1);
String[] FROM = { "*" };
cursor = db.query(true, "tol", FROM,"start='start'",null, "end", null,null, null);
startManagingCursor(cursor);
//startList = new String[cursor.getCount()];
endList = new String[cursor.getCount()];
while(cursor.moveToNext())
{
//String start = cursor.getString(0);
String end = cursor.getString(1);
//startList[listcount] = start;
endList[listcount] = end;
listcount++;
}
if(db != null)
db.close();
} catch (Exception e) {
Toast.makeText(this, "ERROR IN CODE:"+e.toString(), Toast.LENGTH_LONG).show();
}
if (listcount > 0)
{
ArrayList<String> listString = new ArrayList<String>();
for (int i = 0; i < startList.length; i++)
{
listString.add(startList[i]);
}
Spinner spinner = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getBaseContext(),
android.R.layout.simple_spinner_item, listString);
spinner.setAdapter(arrayAdapter);
ArrayList<String> listString1 = new ArrayList<String>();
for (int i = 0; i < endList.length; i++)
{
listString1.add(endList[i]);
}
Spinner spinner1 = (Spinner)findViewById(R.id.spinner2);
ArrayAdapter<String> arrayAdapter1 = new ArrayAdapter<String>(getBaseContext(),
android.R.layout.simple_spinner_item, listString1);
spinner1.setAdapter(arrayAdapter1);
}