我有一个从FragmentActivity扩展的Main活动,如下所示:
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();
}
有两个片段,如下:
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();
...
}
这是CustomFragmentAdapter类:
//liek this: http://stackoverflow.com/questions/8785221/retrieve-a-fragment-from-a-viewpager
class CustomFragmentAdapter extends FragmentStatePagerAdapter{
...
public Fragment getRegisteredFragment(int position){
return registeredFragments.get(posotion);
}
我正在使用此库来显示警告消息:https://github.com/inmite/android-styled-dialogs
为什么当我按下在secondtab片段中显示的正面或负面按钮时,没有发生?