mercredi 28 juillet 2021

My seekbar doesn't work in a BottomSheetDialog

I created a BottomSheetDialog with a checkbox and a SeekBar. I want that if the checkbox is checked, the seekbar can be used. My code works but only if i use setContentView(MyLayout), but that makes the layout appair on screen and i want that it works on the dialog. How can i make it work without that? My code here: Ps: I am sorry for my english, but it isn't my first language.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar=findViewById(R.id.my_toolbar);
    setSupportActionBar(toolbar);
    toolbar.setOverflowIcon(getDrawable(R.drawable.ic_baseline_more_vert_24));


    ImageButton menu_filtri = findViewById(R.id.button_filtri);
    menu_filtri.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(MainActivity.this,R.style.BottomSheetDialogTheme);
            View BottomSheetView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_bottom_sheet,(LinearLayout)findViewById(R.id.bottom_sheet_container));

            bottomSheetDialog.setContentView(BottomSheetView);
            bottomSheetDialog.show();
            setContentView(R.layout.layout_bottom_sheet);

            range_distanza = (CheckBox) findViewById(R.id.next_checkbox);
            seekbar = (SeekBar) findViewById(R.id.range_seekbar);
            set_seekbar();

        }
    });



}

public void set_seekbar() {
    range_distanza.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean ischecked) {
            seekbar.setEnabled(ischecked);
        }
    });
}



Aucun commentaire:

Enregistrer un commentaire