Show SimpleDialogFragment message alert in a fragment
Asked Answered
C

2

0

I have a Main activity that extends from FragmentActivity, like this:

public class Main extends FragmentActivity{
public static FragmentManager fragmentManager;
public static CustomFragmentAdapter mAdapter;
...
//I can access to canAccessFromMain() in SecondTab like this:
((SecondTab)Main.mAdapter.getRegisteredFragment(1)).canAccessFromMain();
}

With two fragments, like this:

public class SecondTab extends Fragment implements ISimpleDialogListener{
...
//Access to objects in Main like this:
googleMap = ((SupportMapFragment)Main.fragmentManager.findFragmentById(R.id.map)).getMap();
...

@Override
public void onPositiveButtonCLicked(int requestedCode){
if(requestedCode == 12}{
//Do something //Problem is here, it's never called!
}
...

public void canAccessFromMain(){
mImageView.setVisibility(View.invisible);
}

private void DoSomething(){
//I test all of these, but not working:
//getActivity(),getActivity().getSupportFragmentManager()
//getActivity(),((SecondTab )Main.mAdapter.getRegisteredFragment(1))).getFragmentManager()
//Main.fragmentManager
SimpleDialogFragment.createBuilder(getActivity(),getActivity().getSupportFragmentManager()
.setTitle("ttt")
.setMessage("mmm")
.setPositiveButtonText("OK").setRequestCode(12)
.setNegativeButtonText("No")
.show();

...
}

And this is CustomFragmentAdapter class:

//liek this: https://mcmap.net/q/57287/-retrieve-a-fragment-from-a-viewpager
class CustomFragmentAdapter extends FragmentStatePagerAdapter{
...
public Fragment getRegisteredFragment(int position){
return registeredFragments.get(posotion);
}

I'm using this library to show a alert message: https://github.com/inmite/android-styled-dialogs

Why when i press positive or negative button that show in secondtab fragment, nothings happed?

Coralloid answered 2/8, 2014 at 21:17 Comment(0)
W
2

You forgot to call method setTargetFragment() in your builder.

Wormy answered 3/8, 2014 at 22:47 Comment(0)
P
0

You should implement an OnClickListener

Pyorrhea answered 2/8, 2014 at 22:37 Comment(1)
The library has own listener that i implemented from ISimpleDialogListener and Override its method onPositiveButtonCLicked.Coralloid

© 2022 - 2024 — McMap. All rights reserved.