-
Notifications
You must be signed in to change notification settings - Fork 377
BasicButtonsCard
Fabio Hellmann edited this page Feb 11, 2016
·
6 revisions
BasicButtonsCard is a simple Card that shows a title, a description, and offers two buttons.
Card card = new Card.Builder(this)
.withProvider(new CardProvider())
.setLayout(R.layout.material_basic_buttons_card)
.setTitle("Card number 4")
.setDescription("Lorem ipsum dolor sit amet")
.addAction(R.id.left_text_button, new TextViewAction(this)
.setText("Izquierda")
.setTextResourceColor(R.color.black_button)
.setListener(new OnActionClickListener() {
@Override
public void onActionClicked(View view, Card card) {
Toast.makeText(mContext, "You have pressed the left button", Toast.LENGTH_SHORT).show();
}
}))
.addAction(R.id.right_text_button, new TextViewAction(this)
.setText("Derecha")
.setTextResourceColor(R.color.accent_material_dark)
.setListener(new OnActionClickListener() {
@Override
public void onActionClicked(View view, Card card) {
Toast.makeText(mContext, "You have pressed the right button", Toast.LENGTH_SHORT).show();
}
}));
.endConfig()
.build();
For title and description, you only need to call the setTitle(String title)
and setDescription(String description)
methods
BasicButtonsCard card = new BasicButtonsCard(context);
card.setTitle("Your title");
card.setDescription("Your description");
The text shown in both buttons can also be set, just by calling BasicButtonsCard.setLeftButtonText(String text)
(or its right equivalent).
card.setLeftButtonText("LEFT");
card.setRightButtonText("RIGHT");
You can also define behaviours for the button pressing. You only need to call BasicImageButtonsCard.setOnLeftButtonPressedListener(OnButtonPressListener)
(or its equivalent for the right button) and define its behaviour.
As you can see, you will receive the View and the Card attached to that View, in order to recover the data from it.
Example:
card.setOnRightButtonPressedListener(new OnButtonPressListener() {
@Override
public void onButtonPressedListener(View view, Card card) {
Toast.makeText( mContext,
"You have pressed the right button",
Toast.LENGTH_SHORT
).show();
}
});