2つのアクティビティAとBを作成します。アクティビティ「A」のSQLiteデータベースとアクティビティ「B」のスピナーからリストビューにデータを入力するリストビューがあります。リストビューからアクティビティ 'B' のスピナーにデータを追加したいのですが、これを行うにはどうすればよいですか。
public class DefineProducts_Activity6 extends Activity {
private com.db_mgmt.DbHelper mHelper;
private SQLiteDatabase dataBase;
private ArrayList<String> products_Id_ArrayList = new ArrayList<String>();
private ArrayList<String> products_Name_ArrayList = new ArrayList<String>();
private ArrayList<String> products_Details_ArrayList = new ArrayList<String>();
private ListView products_List;
private AlertDialog.Builder build;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.define_products_listview);
products_List = (ListView) findViewById(R.id.products_List);
mHelper = new DbHelper(this);
//add new record
findViewById(R.id.btnAdd_DefineProduct).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),
Add_Define_Product.class);
i.putExtra("update", false);
startActivity(i);
}
});
@Override
protected void onResume() {
displayData();
super.onResume();
}
/**
* displays data from SQLite
*/
private void displayData() {
dataBase = mHelper.getWritableDatabase();
Cursor mCursor = dataBase.rawQuery("SELECT * FROM "
+ DbHelper.TABLE_DEFINE_PRODUCT_NAME, null);
products_Id_ArrayList.clear();
products_Name_ArrayList.clear();
products_Details_ArrayList.clear();
if (mCursor.moveToFirst())
{
do
{
products_Id_ArrayList.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_ID)));
products_Name_ArrayList.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_PRODUCTS_NAME)));
products_Details_ArrayList.add(mCursor.getString(mCursor.getColumnIndex(DbHelper.KEY_PRODUCTS_DETAILS)));
} while (mCursor.moveToNext());
}
Product_List_Adapter disadpt = new Product_List_Adapter(DefineProducts_Activity6.this,products_Id_ArrayList, products_Name_ArrayList, products_Details_ArrayList);
products_List.setAdapter(disadpt);
mCursor.close();
}
}