我有一个从 FragmentActivity 扩展的主要活动,如下所示:
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 片段中的正面或负面按钮时,什么都没有发生?