私はthisライブラリを使用してExpandableRecyclerViewを実装しています。ExpandableRecyclerViewグループビュー内のクリックイベントを処理する
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/expandable_list_group_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group Heading" />
<ImageButton
android:id="@+id/expandable_list_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_black_24dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
ライブラリによって処理されていると私はアダプタでのメソッドを介して、リストに要素を追加している崩壊/拡張するためのクリックイベント:グループビューは、次のようになります。ライブラリがコード化された方法、具体的な存在は、アイテムの追加と削除する方法を通知:
が意図したとおりに動作しない伝統的なnotifyDataSetChanged()RecyclerView.Adapterのことに注意してください。代わりに拡張可能なRecyclerViewは、ParentListItemのリストに対する変更をアダプタに通知する機能を備えた通知メソッドのセットを提供します。
notifyParentItemInserted(int型parentPosition)、notifyParentItemRemoved(int型parentPosition)、notifyParentItemChanged(int型parentPosition)、notifyParentItemRangeInserted(int型parentPositionStart、int型ITEMCOUNT個)
私は与えられたグループの削除を処理するためのImageButtonを使用したいですリストから。これを行うには、アダプタメソッドnotifyParentItemRemovedにアクセスする必要があります。
public class MyParentViewHolder extends ParentViewHolder {
TextView groupTitle;
ImageButton deleteButton;
public MyParentViewHolder(View itemView) {
super(itemView);
groupTitle = (TextView) itemView.findViewById(R.id.expandable_list_group_title);
deleteButton = (ImageButton) itemView.findViewById(R.id.expandable_list_delete);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
... // somehow delete
}
});
}
public void bind(...) {
...
}
もしそうなら、どのように私
- アクセス私が削除したいリスト項目になりますので、同様に、私は、グループのViewHolder内のクリックを処理すべきか? ArrayListはAdapterクラスにあります。
- リストを更新しますか?アダプタの通知メソッドを呼び出す必要があります。
ViewHolder内でアダプタを参照する必要がありますか?このように扱うのは正しいとは感じません。そうでない場合は、展開可能なグループビューからクリックイベントをどのように処理できますか?