我创建了 2 个活动 A 和 B。我有 listview,它从活动“A”中的 SQLite 数据库和活动“B”中的 Spinner 填充列表视图中的数据。我想将列表视图中的数据添加到活动“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();
}
}