2

First off, I have this working, but it is not as smooth as I would like. Here is what I am doing:

I have a TimePicker in a fragment, and I have the onTimeChangedListener set so that whenever this changes, it grabs the hour and minute, packages them up in a userInfo object, and passes it back to the activity. The issue is that when I do this, I am creating a new fragment with the new info because I am not sure how else to save all my data. Is there some way to change the onTimeChangedListener to only fire after the ticker date has stopped being changed for 'x' amount of time?

Here is where I set the onTimeChangedListener and pass it back to the Activity:

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_time_calculation, container, false);
    TimePicker userTime = (TimePicker) view.findViewById(R.id.timePicker);
    userTime.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener(){

            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                bUserInfo.settHour(hourOfDay);
                bUserInfo.settMinute(minute);
                timeChanged(bUserInfo);
            }
        });
     return view;
}

public void timeChanged(userInfo userInfo){
    if (mListener != null){
        mListener.timeWasChanged(userInfo);
    }
}

public interface OnFragmentInteractionListener {

    public void timeWasChanged(userInfo userInfo);
}

In the activity, I implement this interface by doing this:

@Override
public void timeWasChanged(userInfo userInfo) {
    if (userInfo != null){
        this.userInfo = userInfo;
    }
    else {
        userInfo = this.userInfo;
    }
    saveUserInfoToSharedPrefs(userInfo);
    FragmentManager fragmentManager = getFragmentManager();
    Fragment newFragment = new TimeCalculation().newInstance(userInfo);
    VISIBLE_FRAGMENT_TAG = newFragment.toString();
    fragmentManager.beginTransaction()
            .replace(R.id.container, newFragment, VISIBLE_FRAGMENT_TAG)
            .setTransition(FragmentTransaction.TRANSIT_NONE)
            .commit();
}

So the heart of my question: Is there a better way to do this? Every time the user changes the time (on a Galaxy S4 at least, which has continuous wheels for the TimePicker), it can't be a continuous swipe, if I swipe the hour up or down, I must pick up my finger to re-swipe after every hour. Same goes with minutes. I am wondering if there is a more elegant way to handle this communication, or if there is a workaround to all of this.

Thank you for your time and effort!

Bwvolleyball
  • 2,593
  • 2
  • 19
  • 31
  • At this point, I'd even take suggestions about how to handle this, because I haven't even gotten any responses. Does anyone know how they would handle this? – Bwvolleyball Aug 01 '14 at 05:08

0 Answers0