DB를 listview에 뿔리고 클릭했을때 이벤트발생하면 DB에 있는 내용을 넘겨줘서 텍스트뷰에 뿌려주는
건데요 listview를 클릭하면 오류가 뜹니다~ㅠㅠ
그냥인텐트하면 실행되어지는데
디버깅 해보니 cursor 하는데서 잘못된거 같은데 정확히 모르겠어요~~
manifest에도 activity 추가도 다했는데요~ㅠㅠ
꼭 답변부탁드립니다~~
/////////////////////////////////////////////////////////////////////////////
public class LocationinforDB extends Activity {
private Cursor mCursor;
private static final int ACTIVITY_CALL=1;
public static final String KEY_ROWID = "_id";
public static final String KEY_NAME = "name";
public static final String KEY_LOCATION = "location";
public static final String KEY_PRICE = "price";
public static final String KEY_LOCATIonINFOR = "locationinfor";
public static final String KEY_LETI = "leti";
public static final String KEY_LonG = "long";
private SQLiteDatabase mDb;
LocationDBHelper mHelper;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subflocation);
mHelper = new LocationDBHelper(this);
Cursor cursor;
SQLiteDatabase db = mHelper.getWritableDatabase();
cursor = db.rawQuery("SELECT * FROM product", null);
startManagingCursor(cursor);
SimpleCursorAdapter Adapter = null;
Adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,
cursor, new String[] { "name", "location" },
new int[] { android.R.id.text1, android.R.id.text2});
ListView list = (ListView)findViewById(R.id.list);
list.setAdapter(Adapter);
list.setClickable(true);
list.setOnItemClickListener(onListClick);
}
private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Cursor c = mCursor;
c.moveToPosition(position); //디버깅하니 여기서 멈추더라구요~~
Intent i = new Intent(LocationinforDB.this, Lolistdetail.class);
i.putExtra(KEY_ROWID, id);
i.putExtra(KEY_NAME, c.getString(
c.getColumnIndexOrThrow(KEY_NAME)));
i.putExtra(KEY_LOCATION, c.getString(
c.getColumnIndexOrThrow(KEY_LOCATION)));
i.putExtra(KEY_PRICE, c.getString(
c.getColumnIndexOrThrow(KEY_PRICE)));
i.putExtra(KEY_LOCATIONINFOR, c.getString(
c.getColumnIndexOrThrow(KEY_LOCATIONINFOR)));
i.putExtra(KEY_LETI, c.getString(
c.getColumnIndexOrThrow(KEY_LETI)));
i.putExtra(KEY_LONG, c.getString(
c.getColumnIndexOrThrow(KEY_LONG)));
startActivity(i);
}
};
}
class LocationDBHelper extends SQLiteOpenHelper {
public LocationDBHelper(Context context) {
super(context, "locationinfor1.db", null, 1);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE product ( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"name TEXT, location TEXT, price TEXT, leti TEXT, long TEXT, locationinfor TEXT);");
db.execSQL("INSERT INTO product VALUES (null, '수어장대','남한산성' ,1000 , 37464282, 127171933, '역사적인 장소이며 높지않은 산으로 연인이가기 좋음');");
db.execSQL("INSERT INTO product VALUES (null, '율동공원','성남서현' , 0, 37380331, 127148887, '자전거를 탈수도 있고 번지점프를 즐길 수있고 피크닉하기 좋음');");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS product");
onCreate(db);
}
}
//////////////////////////////////////////////////////////////////////////////////
public class Lolistdetail extends Activity{
private TextView mName;
private TextView mLocation;
private TextView mPrice;
private TextView mLocationinfor;
private Long mRowId;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lolistdetail);
mName= (TextView) findViewById(R.id.vname);
mLocation= (TextView) findViewById(R.id.vlocation);
mPrice= (TextView) findViewById(R.id.vprice);
mLocationinfor= (TextView) findViewById(R.id.vlocationinfor);
mRowId= null;Bundle extras = getIntent().getExtras();
if (extras != null) {
String name = extras.getString(LocationinforDB.KEY_NAME);
String location = extras.getString(LocationinforDB.KEY_LOCATION);
String price = extras.getString(LocationinforDB.KEY_PRICE);
String locationinfor = extras.getString(LocationinforDB.KEY_LOCATIONINFOR);
mRowId= extras.getLong(LocationinforDB.KEY_ROWID);
if (name != null) {mName.setText(name);}
if (location != null) {mLocation.setText(location);}
if (price != null) {mPrice.setText(price);}
if (locationinfor != null) {mLocationinfor.setText(locationinfor);}
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
}
}
List에는 두개만 대표로 뿌려지거든요~ DB에가면 옮겨줘야할 칼럼이 더있어서요~~ DB에서 자료를 다음 엑티비티로 옮겨야해요~ㅠㅠ
DB에서 받은 값을 String 으로 받아서 다른 엑티비티를 넘겨 주라는 거에요??
자답입니다~~
SQLiteDatabase db = mHelper.getWritableDatabase();
mCursor = db.rawQuery("SELECT * FROM product", null);
Cursor c =mCursor;
이렇게 하니 돌아가네요^^
조언감사합니다(__)꾸벅




List클릭 ->DB
루프처럼 보이지 않나요?