我目前正在尝试实现 Android BetterPickers 库(https://github.com/derekbrameyer/android-betterpickers)。我已经能够显示要求用户选择时间的选择器,但是没有调用界面提供的方法。该方法位于https://github.com/derekbrameyer/android-betterpickers/blob/master/sample/src/com/doomonafireball/betterpickers/sample/activity/hmspicker/SampleHmsDefault.java的第 43 行。
这是我的代码的样子。我的代码和提供的示例之间的主要区别在于,我的代码是在 Fragment 中执行的,而不是在 Activity 中执行的(github 示例中的第 35 行)。我使用 getActivity().getSupportFragmentManager() 而不是 getSupportFragmentManager()。为什么不调用 onDialogHmsSet 方法?
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.doomonafireball.betterpickers.hmspicker.HmsPickerBuilder;
import com.doomonafireball.betterpickers.hmspicker.HmsPickerDialogFragment.HmsPickerDialogHandler;
import com.example.hiittimer.R;
public class NewWorkout extends Fragment implements OnClickListener, HmsPickerDialogHandler {
private View view;
private Button btnSetOn, btnSetOff;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_activity_new_workout, container, false);
viewHolder = new ViewHolder();
setViews();
return view;
}
private void setViews(){
btnSetOff = (Button) view.findViewById(R.id.btn_set_on);
btnSetOn = (Button) view.findViewById(R.id.btn_set_off);
btnSetOff.setOnClickListener(this);
btnSetOn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_set_on:
HmsPickerBuilder hpb = new HmsPickerBuilder().
setStyleResId(R.style.BetterPickersDialogFragment)
.setFragmentManager(getActivity().getSupportFragmentManager();
hpb.show();
break;
case R.id.btn_set_off:
break;
default:
break;
}
}
@Override
public void onDialogHmsSet(int reference, int hours, int minutes, int seconds) {
Assert.assertTrue(false);
}
}