먼저 소스
//데이터 조회
case R.id.select:
db = mHelper.getReadableDatabase();
// 안드로이드의 Cursor 클래스는 ResultSet과 유사하다.
Cursor cursor1;
// query 메서드로 읽기
//cursor = db.query("customer", new String[]
//{"name", "adress", "age"}, null, null, null, null, null);
// SQL 명령으로 읽기
cursor1 = db.rawQuery("SELECT name, adress FROM Customer", null);
String[] Result = new String[1];
while (cursor1.moveToNext()) {
int i =0;
String name = cursor1.getString(0);
String adress = cursor1.getString(1);
Result[i] += (name + "" + adress + "\n");
Result[i] = Result[i].substring(4);
}
if(cursor1.getCount() > 0){
itemsDBAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Result);
listview.setAdapter(itemsDBAdapter);
//listview.setChoiceMode(listview.CHOICE_MODE_SINGLE);
}
else {
mText.setText("데이터가 없습니다");
}
listview.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// TODO Auto-generated method stub
/* SQLiteDatabase db;
db = mHelper.getReadableDatabase();
Cursor cursor;
String str = new String();
cursor = db.rawQuery("SELECT adress FROM Customer", null);
// String name = cursor.getString(0);
String adress = cursor.getString(1);
str += ( adress + "\n");*/
//cursor.moveToPosition(position);
//String str = cursor.getString(cursor.getColumnIndex("address"));
String str = (String)itemsDBAdapter.getItem(position);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(str));
MainActivity.this.startActivity(intent);
}
});
cursor1.close();
mHelper.close();
break;
}
}
}
일단 과제는 아님 </pre>
//데이터 조회
case R.id.select:
db = mHelper.getReadableDatabase();
// 안드로이드의 Cursor 클래스는 ResultSet과 유사하다.
Cursor cursor1;
// query 메서드로 읽기
//cursor = db.query("customer", new String[]
//{"name", "adress", "age"}, null, null, null, null, null);
// SQL 명령으로 읽기
cursor1 = db.rawQuery("SELECT name, adress FROM Customer", null);
String[] Result = new String[1];
while (cursor1.moveToNext()) {
int i =0;
String name = cursor1.getString(0);
String adress = cursor1.getString(1);
Result[i] += (name + "" + adress + "\n");
Result[i] = Result[i].substring(4);
}
if(cursor1.getCount() > 0){
itemsDBAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Result);
listview.setAdapter(itemsDBAdapter);
//listview.setChoiceMode(listview.CHOICE_MODE_SINGLE);
}
else {
mText.setText("데이터가 없습니다");
}
listview.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
// TODO Auto-generated method stub
/* SQLiteDatabase db;
db = mHelper.getReadableDatabase();
Cursor cursor;
String str = new String();
cursor = db.rawQuery("SELECT adress FROM Customer", null);
// String name = cursor.getString(0);
String adress = cursor.getString(1);
str += ( adress + "\n");*/
//cursor.moveToPosition(position);
//String str = cursor.getString(cursor.getColumnIndex("address"));
String str = (String)itemsDBAdapter.getItem(position);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(str));
MainActivity.this.startActivity(intent);
}
});
cursor1.close();
mHelper.close();
break;
}
}
}
일단 과제는 아님 </pre>
이런데
SQLiteDB를 이용해서
리스트뷰에서 조회를 하고
리스트뷰의 항목을 클릭하면 웹브라우저가 열리게 만들고 싶은데
클릭해도 반응도 없고
새로운항목 삽입할때마다 자꾸 0번항목에다가 스트링을 복사해
밤도 새봤고 인터넷 온종일 뒤져도 안나와;;;
능력자게이들 좀 도와줘 ㅠㅠ
댓글 0