Refreshing parent fragment on PopupWindow.dismiss

牧云@^-^@ 提交于 2019-12-06 14:16:38

Never got to the point where I could refresh the parent window directly on the child PopupWindow dismiss. The final solution (workaround) was to use fragmentmanager replace() after an onTouch event from the spinner only when a static flag (iSpeciesRefresh) had been set that indicated a modified SQL spinner lookup table.

public class dataCapture extends Fragment implements OnClickListener {
String szSpecies;
static public int iSpeciesRefresh = 1;
Spinner spinnerSpecies;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.data_capture, container, false);
...
    spinnerSpecies = (Spinner) v.findViewById(R.id.spinnerSpeciesxml);

    spinnerSpecies.setOnTouchListener(new View.OnTouchListener() {//refreshes fragment as needed...
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (iSpeciesRefresh == 1) {//this is application default
                //do nothing
            } else if (iSpeciesRefresh == 0) {//value is reset to "0" at SAVE, UPDATE, or DELETE in speciesPopupWindow.
                refreshDataCapture();
                iSpeciesRefresh = 1;
            }
            return false;
        }
    });
...
}    
public void refreshDataCapture() {
    Fragment currentFragment = (dataCapture) getFragmentManager().findFragmentByTag("data_capture");
    if (currentFragment == null) {
        currentFragment = new dataCapture();
    } else if (currentFragment != null) {
        getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        getFragmentManager().beginTransaction().replace(R.id.fragment_placeholder, new dataCapture(), "data_capture").addToBackStack(null).commit();       
    }
}

In your onCreateView and onViewCreated methods, you do btnPopup.setOnClickListener(this);, but then in your showPopup class' init() method, you overwrite your fragment as the listener and instead assign a new anonymous listener. My guess is that you need to rework how you assign your listener and make sure you don't overwrite it like that.

P.S. For maintainability's sake (and the sanity of other developers who look at your code), it's convention to name classes with upper camel case and they should not contain verbs. Something like MyCustomPopup would be better.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!