单击复选框,更新特定项目上的数据库-android

单击复选框,更新特定项目上的数据库-android,android,listview,checkbox,Android,Listview,Checkbox,我想在单击我的复选框时更新我的数据库 但我不知道如何通过单击复选框来捕获项目列表中的项目编号 这是我的密码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bucket_item); int value = getIntent().getExtras().getInt("buc

我想在单击我的复选框时更新我的数据库

但我不知道如何通过单击复选框来捕获项目列表中的项目编号

这是我的密码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bucket_item);

int value = getIntent().getExtras().getInt("bucketno");
DatabaseHandler myDbHelper = new DatabaseHandler(this);

BucketItem[] bucketItems = myDbHelper.getAllContacts(value);
BucketItemAdapter adapter = new BucketItemAdapter(this, R.layout.row_item, bucketItems);

listView2 = getListView();
View header = (View) getLayoutInflater().inflate(R.layout.row_header, null); 
listView2.addHeaderView(header);
listView2.setAdapter(adapter);
}

活动\u bucket\u item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">    

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1"
    />

</LinearLayout>
方法,但我不能,因为我计划在用户单击项目列表时使用此方法,说明和图像将弹出


谢谢

当通过setTag()方法在适配器中创建视图时,您可以在复选框中添加一些行Id。然后在处理检查状态更改时提取它。大概是这样的:

public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    int id = (Integer)buttonView.getTag();
}
onListItemClick(ListView listView, View v, int position,
            long id)
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    int id = (Integer)buttonView.getTag();
}