I have an activity with two fragments: one for displaying products in a gridview, and the other for displaying products that the user adds to the order (ListFragment). When the user clicks on the product in the form of a grid, I need to display a dialog box (DialogFragment), in which I request the quantity of the required product. Then, when the user clicked the accept button in the dialog box, I want the product to appear in the list.
On the one hand, I have to pass the object-object into the dialog in order to show its name as the title of the dialog (for example). So, I did it like this:
public static class ProductDialog extends DialogFragment { static ProductDialog newInstance(ProductVO product) { ProductDialog f = new ProductDialog(); Bundle args = new Bundle(); args.putSerializable("product", product); f.setArguments(args); return f; } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { ProductVO product = (ProductVO) getArguments().getSerializable("product"); return new AlertDialog.Builder(getActivity()) .setIcon(R.drawable.ic_dialog_add) .setTitle(R.string.add_product) ... .setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } } ) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } } ) .create(); } }
I think this is okey, correct me if I am wrong. But then in the onClick event of the positive button, I have to get the amount entered in the dialog box, and then transfer it to another fragment (ListFragment), and then it should be displayed in the list instantly.
How can i do this?
Thanks in advance
olistic
source share