0
我想實現我的onItemSelected,這樣當用戶單擊複選框時,它將被標記爲「已選中」 ,然後更新列DBContract.EntryColumns.IS_CHECKED以進行檢查(將其設置爲1 )。一切工作正常,但問題是我不知道如何在實現onItemSelected方法 。請有人告訴我如何解決這個問題。複選框如何實現 - android recyclerview
這裏是我的Activity和list_item_book.xml,其中CheckBox被定義。
public class MainActivity extends AppCompatActivity implements
BookAdapter.OnItemClickListener,
View.OnClickListener {
private BookAdapter mAdapter;
private CheckBox mCheckBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = new BookAdapter(null);
mAdapter.setOnItemClickListener(this);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setAdapter(mAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
/* This method will be called when I Click on checkboxes */
@Override
public void onItemSelected(boolean active, int position) {
//what should I write here?
// DBContract.EntryColumns.IS_CHECKED
//
}
}
//list_item_book.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>