MainActivity.java :

public class MainActivity extends AppCompatActivity implements View.OnClickListener { private BottomSheetBehavior mBottomSheetBehavior; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View bottomSheet = findViewById( R.id.bottom_sheet ); Button button1 = (Button) findViewById( R.id.button_1 ); Button button2 = (Button) findViewById( R.id.button_2 ); Button button3 = (Button) findViewById( R.id.button_3 ); button1.setOnClickListener(this); button2.setOnClickListener(this); button3.setOnClickListener(this); mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); mBottomSheetBehavior.setHideable(true); mBottomSheetBehavior.setPeekHeight(300); //mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(View bottomSheet, int newState) { Toast.makeText(getApplicationContext(), "onStateChanged() is called.", Toast.LENGTH_SHORT).show(); // this method is called forever i dont understand why??? } @Override public void onSlide(View bottomSheet, float slideOffset) { Toast.makeText(getApplicationContext(), "onStateChanged() is called. in onSlide()", Toast.LENGTH_SHORT).show(); // this method is also called forever i dont understand why??? } }); } @Override public void onClick(View v) { switch( v.getId() ) { case R.id.button_1: { mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); break; } case R.id.button_2: { mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); break; } case R.id.button_3: { mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); break; } } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.