我想设置一个日期间隔,当用户按下结束日期时,绘制一个图表。我遇到的问题是图表是在开始日期和结束日期绘制的。
我试图设置一个布尔变量或一个整数来决定何时绘制图表,但由于我使用“DatePickerFragmet”中的“onDateSet”,我无法修改它的参数......我在这里粘贴我的代码以提供帮助澄清我要解释的内容:
在我的主要活动中,我有:
startDate.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
for (int i=0; i<2; i++){
showDatePickerDialog(v,i);
}
}
});
public void showDatePickerDialog(View v, int i) {
DialogFragment newFragment = new DatePickerFragment();
newFragment.show(getFragmentManager(), "datePicker");
}
然后在一个新类上我调用 onDateSet:
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
LineGraph lineGraph = new LineGraph();
lineGraph.run(getActivity());
}
... 选择最终日期后如何绘制图表?