'A리스트뷰' 가 있고 'B리스트뷰' 가 있습니다.
그리고 DB에 '가테이블' 이 있고 '나테이블'이 있습니다
가테이블 자료를 A리스트뷰에 띄우도록 만든 상태 입니다.
A리스트뷰에서 목록을 클릭 하면 해당목록을 나테이블 에추가 하여
나테이블의 자료는 B리스트뷰에 띄워 주려고 합니다.
클릭 이벤트를 어떻게 넣어야 할지 도통 모르겠습니다.
A리스트 B리스트
--------------------------------------------------------------------
고구마 1000 → 클릭 ↘ 깍두기 1000
고구미 2000 ↓ 깍두이 2000
고구묘 3000 ↘ 깍두삼 3000
→ 고구마 1000
요런식으로 가능할까요?
아래는 소스 입니다.
--------------------------가테이블----------------------------------
public class DB2Activity extends Activity {
productDBHelper mHelper ;
final Context contextOfThisActivity = this;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mHelper = new productDBHelper(this);
Cursor cursor;
SQLiteDatabase db = mHelper.getWritableDatabase();
cursor =db.rawQuery( "SELECT * FROM aaa", null ) ;
startManagingCursor( cursor );
SimpleCursorAdapter Adapter = null;
Adapter = new SimpleCursorAdapter( this,
R.layout.listmodel ,
cursor, new String[] { "name", "price" },
new int[] {R.id.textView1, R.id.textView2 } );
ListView list =( ListView ) findViewById (R.id.mainlist );
list.setAdapter(Adapter);
Button btn = (Button) findViewById(R.id.but);
btn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent =new Intent(DB2Activity.this, DB2Activity2.class);
startActivity(intent);
}
});
}
}
//dsfer
class productDBHelper extends SQLiteOpenHelper {
public productDBHelper ( Context context ) {
super ( context, "aaa.db", null, 1 );
}
@Override
public void onCreate ( SQLiteDatabase db ) {
db.execSQL("CREATE TABLE aaa( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
" name TEXT, price INTEGER) ;" ) ;
db.execSQL("CREATE TABLE bbb( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
" name TEXT, price INTEGER) ;" ) ;
db.execSQL("INSERT INTO aaa VALUES (null, '고구마', 900) ;" );
db.execSQL("INSERT INTO aaa VALUES (null, '고구미', 900) ;" );
db.execSQL("INSERT INTO aaa VALUES (null, '고구묘', 900) ;" );
db.execSQL("INSERT INTO aaa VALUES (null, '고구무', 900) ;" );
db.execSQL("INSERT INTO aaa VALUES (null, '고구바', 900) ;" );
db.execSQL("INSERT INTO aaa VALUES (null, '고도바', 900) ;" );
db.execSQL("INSERT INTO aaa VALUES (null, '고이바', 900) ;" );
db.execSQL("INSERT INTO aaa VALUES (null, '고규바', 1900) ;" );
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS aaa");
onCreate(db);
}
protected void onListItemClick(ListView l, View v, int position, long id,SQLiteDatabase db) {
Log.e("position", Integer.toString(position));
}
}
--------------------------나테이블----------------------------------
public class DB2Activity2 extends Activity {
bbbDBHelper mHelper ;
final Context contextOfThisActivity = this;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
mHelper = new bbbDBHelper(this);
Cursor cursor;
SQLiteDatabase db = mHelper.getWritableDatabase();
cursor =db.rawQuery( "SELECT * FROM bbb", null ) ;
startManagingCursor( cursor );
SimpleCursorAdapter Adapter2 = null;
Adapter2 = new SimpleCursorAdapter( this,
R.layout.listmodel2 ,
cursor, new String[] { "name", "price" },
new int[] {R.id.textView1, R.id.textView2 } );
ListView list =( ListView ) findViewById (R.id.mainlist2 );
list.setAdapter(Adapter2);
Button btn = (Button) findViewById(R.id.but2);
btn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent =new Intent(DB2Activity2.this, DB2Activity.class);
startActivity(intent);
}
});
}
}
//dsfer
class bbbDBHelper extends SQLiteOpenHelper {
public bbbDBHelper ( Context context ) {
super ( context, "bbb.db2", null, 1 );
}
@Override
public void onCreate ( SQLiteDatabase db ) {
db.execSQL("CREATE TABLE bbb( _id INTEGER PRIMARY KEY AUTOINCREMENT, " +
" name TEXT, price INTEGER) ;" ) ;
db.execSQL("INSERT INTO bbb VALUES (null, '가고구마', 900) ;" );
db.execSQL("INSERT INTO bbb VALUES (null, '가고구미', 900) ;" );
db.execSQL("INSERT INTO bbb VALUES (null, '가고구묘', 900) ;" );
db.execSQL("INSERT INTO bbb VALUES (null, '가고구무', 900) ;" );
db.execSQL("INSERT INTO bbb VALUES (null, '가고구바', 900) ;" );
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS bbb");
onCreate(db);
}
}




아시는분이 없나봐요..ㅠㅠ
질문이 잘못된건가...