[General Questions and Answers] wisdomofmetis:
Since this site does not allow me to post to Developer forum, i post this Android Software development related question here.

I asked a question on Stackoverflow however nobody answered it. So i'm asking the same question here.

Its question topic is the same in the stackoverflow. Since i'm new i couldn't share the link here now.

I copy paste it below :

I developed a bottom sheet with the source codes shown below. However, when i change state of bottom sheet(by changing its state collapsed, expanded, or hide) onStateChanged and onSlide method is called forever. I don't understand why. Is this behaviour normal?

MainActivity.java

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private BottomSheetBehavior mBottomSheetBehavior;

[MENTION=439709]override[/MENTION]

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() {

[MENTION=439709]override[/MENTION]

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???

}

[MENTION=439709]override[/MENTION]

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???

}

});

}

[MENTION=439709]override[/MENTION]

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;

}

}

}

}

activity_main.xml

<ScrollView

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:paddingTop="24dp">

<Button

android:id="@+id/button_1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Button 1"

android:padding="16dp"

android:layout_margin="8dp"

android:textColor="@android:color/white"

android:background="@android:color/holo_green_dark"/>

<Button

android:id="@+id/button_2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="16dp"

android:layout_margin="8dp"

android:text="Button 2"

android:textColor="@android:color/white"

android:background="@android:color/holo_blue_light"/>

<Button

android:id="@+id/button_3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="16dp"

android:layout_margin="8dp"

android:text="Button 3"

android:textColor="@android:color/white"

android:background="@android:color/holo_red_dark"/>

</LinearLayout>

</ScrollView>

<android.support.v4.widget.NestedScrollView

android:id="@+id/bottom_sheet"

android:layout_width="match_parent"

android:layout_height="350dp"

android:clipToPadding="true"

android:background="@android:color/holo_orange_light"

app:layout_behavior="android.support.design.widget.BottomSheetBehavior"

>

<TextView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:text="@string/ipsum"

android:padding="16dp"

android:textSize="16sp"/>

</android.support.v4.widget.NestedScrollView>

Thanks in advance...