你好!
我刚开始使用 Android 我有一个程序,它有一个类(扩展 DialogFragment)和一个活动。如何将数据从类发送到android中的活动以便显示?我通过二传手尝试了它,但我不确定这是否是正确的方法?
public class MyDialogFragment extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
MainActivity main = new MainActivity();
main.setHour(hourOfDay); // SETTER METHOD HERE.
}
}
实际上我还有一个问题:在android开发中应该在哪里进行计算?假设我需要在显示结果之前对 hourOfDay 进行一些繁重的计算。是否应该在 MyDialogFragment 类中完成(所以我的活动仅用于显示结果,仅此而已)?
非常感谢!