Reputation: 511
I am trying to implement BottomSheet to my application. I am learning android. I have implemented it as per instruction given in library page here. I have used java code like below.
findViewById(R.id.butShare).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new BottomSheet.Builder(QuoteViewActivity.this)
.setSheet(R.menu.grid_sheet)
.grid()
.setTitle("Lets Some Fun")
.setListener(QuoteViewActivity.this)
.show();
}
});
but I am getting error like
The method setListener(BottomSheetListener) in the type BottomSheet.Builder is not applicable for the arguments (QuoteViewActivity)
I have created menu xml called grid_sheet in menu folder as well. How can I make that menu working ?
Upvotes: 1
Views: 190
Reputation: 3455
The error is with setListener(QuoteViewActivity.this). SetListener() expects a BottomSheetListener not an Activity context. Try setListener(new BottomSheetListener()) & override the interface methods like given below.
new BottomSheet.Builder(MainActivity.this)
.setSheet(R.menu.menu)
.grid()
.setTitle("Lets Some Fun")
.setListener(new BottomSheetListener() {
@Override
public void onSheetShown(@NonNull BottomSheet bottomSheet) {
}
@Override
public void onSheetItemSelected(@NonNull BottomSheet bottomSheet, MenuItem menuItem) {
if(menuItem.getItemId() == R.id.share) {
Toast.makeText(MainActivity.this, "Share" , Toast.LENGTH_LONG).show();
}
}
@Override
public void onSheetDismissed(@NonNull BottomSheet bottomSheet, int i) {
}
})
.show();
Upvotes: 1
Reputation: 20950
The Problem is here
.setListener(QuoteViewActivity.this)
you have setListener on that like this
.setListener(this)
Upvotes: 0
Reputation: 1667
In new BottomSheet.Builder(QuoteViewActivity.this)
pass your activity context saved in onCreate
method or in fragment saved in onAttach(Context mContext)
method.
Hope this helps.
Upvotes: 0