I'm trying to make a recyclerview filter based ChipGroup & Chip
I'm use fragment on my app, so, the fragment who contain the RecyclerView contain a frameLayout who inflate the ChipGroup filter fragment
I'm trying to trigger a listener when the user unselect all chip inside ChipGroup (I've already put listener on chip for trigger when chip are checked by user)
I've already put some listener on chipgroup but no one are trigered
FilterFragment.java
public class FilterFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
public ChipGroup chipGroup;
// TODO: Rename and change types of parameters
public View.OnClickListener chipClickListener;
private OnFragmentInteractionListener mListener;
public FilterFragment() {
// Required empty public constructor
}
public static FilterFragment newInstance(View.OnClickListener
param1) {
CoachFilterFragment fragment = new CoachFilterFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup
container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_filter,
container, false);
this.chipGroup = view.findViewById(R.id.chipGroup);
for(Skill skill : ((MainActivity)getContext()).api.skills){
Chip chip = new Chip(getContext());
chip.setId(skill.getId());
chip.setText(skill.getName());
chip.setOnClickListener(chipClickListener);
chip.setCheckable(true);
chipGroup.addView(chip);
}
chipGroup.setOnCheckedChangeListener((chipGroup, id) -> {
Log.d("test","ok");
});
return view;
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
FilterFragment.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".Fragment.FilterFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</com.google.android.material.chip.ChipGroup>
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
Someone have any idea why any listener are not triggered by my ChipGroup?Maybe I'm missing some parameter or something?
Log.d("test","ok");
in your first listener. – OsburnsingleSelection="true"
. – Chewning