Reputation: 71
the onClickListener of my FloatingActionButton and Toolbar Icon are not working. Here is the code:
floatingActionButton = findViewById(R.id.pausebutton);
floatingActionButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EventHandlerClass.releaseMediaPlayer();
}
});
search_ico=findViewById(R.id.search_ico);
search_ico.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this,searchActivity.class));
}
});
It is weird because the "new OnClickListener()" is greyed out like this:
My clicks are going through the FloatingActionButton, here is the code:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
android:layout_marginBottom="60dp"
android:src="@drawable/paused"
app:fabSize="normal"
app:backgroundTint="#38464E"
app:elevation="20dp"
android:id="@+id/pausebutton"/>
I have absolutely no Idea what is wrong, looks right to me. Does anyone have some Ideas what I could try?
Upvotes: 0
Views: 77
Reputation: 71
I fixed it my own, the problem was that I had this line after the onClickListeners:
setContentView(R.layout.activity_main);
But this line hast to be right at the top of the OnCreate
Upvotes: 1
Reputation: 2019
You can click on it and press option + Enter
. The IDE will tell you it can be replace with lambda
it can make the code more clear
Upvotes: 0