From my Recylerview Adapter
, there are multiple buttons in every Items,
What I want is to show the DialogFragment as confirmation
when they are clicked and execute a different methods/actions when the positiveButton
is clicked.
The problem is I don't know how can I have or how can I implement a callback when the positiveButton
is clicked and can execute a different methods or actions according to what button is to be clicked on every items.
e.g.
On my Adapter Class
@Override
public void onBindViewHolder(final PageOnlineAdapter.TheViewHolder holder, final int position) {
holder.btn_start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = ConfirmationDialog.newInstance(TITLE,CONTENT); //Initialize DialogFragment with a specific Title and Content
newFragment.show(((AppCompatActivity)contextView).getSupportFragmentManager(), TAG);
/*
if positiveButton is clicked
=>execute method/action here
*/
}
);
holder.btn_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = ConfirmationDialog.newInstance(TITLE,CONTENT); //Initialize DialogFragment with a specific Title and Content
newFragment.show(((AppCompatActivity)contextView).getSupportFragmentManager(), TAG);
/*
if positiveButton is clicked
=>execute method/action here
*/
}
);
holder.btn_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = ConfirmationDialog.newInstance(TITLE,CONTENT); //Initialize DialogFragment with a specific Title and Content
newFragment.show(((AppCompatActivity)contextView).getSupportFragmentManager(), TAG);
/*
if positiveButton is clicked
=>execute method/action here
*/
}
);
holder.btn_remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment newFragment = ConfirmationDialog.newInstance(TITLE,CONTENT); //Initialize DialogFragment with a specific Title and Content
newFragment.show(((AppCompatActivity)contextView).getSupportFragmentManager(), TAG);
/*
if positiveButton is clicked
=>execute method/action here
*/
}
);
}
Here's my DialogFragment Class
public class ConfirmationDialog extends DialogFragment {
public static ConfirmationDialog newInstance(String title, String description) {
ConfirmationDialog frag = new ConfirmationDialog();
Bundle args = new Bundle();
args.putString("title", title);
args.putString("description", description);
frag.setArguments(args);
return frag;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
String title = getArguments().getString("title");
String description = getArguments().getString("description");
return new AlertDialog.Builder(getActivity())
//.setIcon(R.drawable.alert_dialog_icon)
.setTitle(title)
.setMessage(description)
.setPositiveButton("CONTINUE",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//How to tell when this positiveButton is clicked
}
}
)
.setNegativeButton("CANCEL",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//How to tell when this negativeButton is clicked
}
}
)
.create();
}
}