I tried to add onClick to my custom toast button, but the button doesn't work. Please I need help
final Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
View custom_view = getLayoutInflater().inflate(R.layout.search_snackbar, null);
Button action = custom_view.findViewById(R.id.sb_action);
action.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View p1) {
//run code on click
}
});
toast.setGravity(Gravity.FILL_HORIZONTAL|Gravity.BOTTOM, 0, 0);
toast.setView(custom_view);
toast.show();
Image of my custom toast with button :