android get selected复选框显示在ListView中
我正在尝试制作一个应用程序,在该应用程序中,我使用现有数据库中的一些产品填充我的listView,目前为止效果良好:) 现在,我在每个产品行上都有一个复选框,单击该复选框时,我希望获得该产品的引用 我是新手,请帮帮我。代码如下:android get selected复选框显示在ListView中,android,listview,checkbox,Android,Listview,Checkbox,我正在尝试制作一个应用程序,在该应用程序中,我使用现有数据库中的一些产品填充我的listView,目前为止效果良好:) 现在,我在每个产品行上都有一个复选框,单击该复选框时,我希望获得该产品的引用 我是新手,请帮帮我。代码如下: public class NewListPage extends MainAppPage { protected TextView productName; protected TextView productPrice; protected
public class NewListPage extends MainAppPage {
protected TextView productName;
protected TextView productPrice;
protected CheckBox checkBox;
protected Database db;
public ListView listView;
public Context context;
protected boolean isChecked;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.existing_product_listview);
db = new Database(this);
productName = (TextView) findViewById(R.id.new_list_productName);
productPrice = (TextView) findViewById(R.id.new_list_productPrice);
listView = (ListView) findViewById(R.id.existing_product_listView);
checkBox = (CheckBox) findViewById(R.id.new_list_productChecked);
populateListView();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.menu_main_saveItem) {
/* WHEN I CLICK ON THE SAVE ITEM I WANT TO GET THE REFERENCE TO THE PRODUCT THAT IS CHECKED HERE*/
}
return super.onOptionsItemSelected(item);
}
private void populateListView(){
//get all rows from DB;
Cursor cursor = db.getAllRows();
// get the product from the product table & price from price table
String[] from = new String[] {Database.PRODUCT, Database.PRICE};
int[] to = new int[] {R.id.new_list_productName, R.id.new_list_productPrice};
SimpleCursorAdapter cursorAdapter;
cursorAdapter = new SimpleCursorAdapter(this,R.layout.new_list_page, cursor, from, to,0);
ListView listView = (ListView) findViewById(R.id.existing_product_listView);
listView.setAdapter(cursorAdapter);
cursorAdapter.notifyDataSetChanged();
}
}
选中复选框后,将项目详细信息添加到ArrayList>arr_main=new ArrayList>() 以id为参考在arraylist中插入和删除产品
并将最终的arraylist传递给另一个列表视图,以填充所选项目的列表视图。使用xml编写android:checked=“true”或编程复选框。setChecked(true);你到底想要什么?当我点击复选框,然后从工具栏(R.id.menu\u main\u saveItem)点击保存项时,我想要得到所有选中的产品,并将它们放入一个新列表中。这个应用程序是一个购物清单,有一个现有的数据库。你能告诉我具体的操作方法吗?我在这方面没有太多经验。如果某人