The Reject dialog closes the operation

My PanelActivity contains a recyclerView with a list of items. Each item has a click event. This click will open DetailsActivity .

DetailsActivity has a floatActionButton that opens a full-screen dialog (my DetailDialogFragment extends DialogFragment ).

DetailDialogFragment has an Up / Home button with firing.

Problem: if the user clicks the "Up" button, the dialog is rejected, and DetailsActivity disappears, and the application returns to PanelActivity .

Possible reason. Below the Up button of the dialog box is the Up button in the DetailsActivity . Is it possible to fire two click events when the dialog is completed and both have the Up button in the same place?




Edit: show code.

Open DetailsActivity from PanelActivity (by clicking one item in recyclerView).

 Intent intent = new Intent(context, DetailsActivity.class); intent.putExtra("headerCode", headerCode.getText()); context.startActivity(intent); 

The Up button in the Details section.

 @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar Up/Home button case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } 

Open the full-screen dialog in the DetailsActivity section.

 private void showCreateDetailDialog() { FragmentManager fragmentManager = getSupportFragmentManager(); DetailDialogFragment newFragment = new DetailDialogFragment(); // The device is smaller, so show the fragment fullscreen FragmentTransaction transaction = fragmentManager.beginTransaction(); // For a little polish, specify a transition animation transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); // To make it fullscreen, use the 'content' root view as the container // for the fragment, which is always the root view for the activity transaction.add(android.R.id.content, newFragment) .addToBackStack(null).commit(); } 

And finally, the Up button in DetailDialogFragment.

 @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.save) { validateForm(); return true; } else if (id == android.R.id.home) { // handle close button click here dismiss(); return true; } return super.onOptionsItemSelected(item); } 
+2
android android-dialogfragment up-button
Oct 31 '16 at 21:42
source share
2 answers

I have not tested it, but I think the problem is here where you call the dismiss function (). You may first need a link to DialogFragment. I think that technically you just call this.dismiss(); where this is equal to the activity in which you work.

 @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.save) { validateForm(); return true; } else if (id == android.R.id.home) { // handle close button click here dismiss(); // problem is with this call return true; } return super.onOptionsItemSelected(item); } 

You can try something like this:

 private DetailDialogFragment detailFragment; private void showCreateDetailDialog() { detailFragment = new DetailDialogFragment(); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.add(android.R.id.content, newFragment).addToBackStack(null).commit(); } 

and now inside onOptionsItemSelected() :

 @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.save) { validateForm(); return true; } else if (id == android.R.id.home) { // handle close button click here detailFragment.dismiss(); return true; } return super.onOptionsItemSelected(item); } 
+1
Nov 10 '16 at 15:26
source share

No, I think this is not possible, maybe your deviceโ€™s problem is to test it on an Android emulator or another device. Can you share your code to try to help you?

0
Oct 31 '16 at 22:56
source share



All Articles