I have two class ,I want to apply a function inside one of them. At the same time, apply the function to another class. In a sense: call class ClassTimePickerDialogto from inside class MainActivity to show an hour. And after pressing the button inside the clock. I'm doing override for function onTimeSet. Then it runs out of work inside class Mainactivity. Then it executes the function finsh.
class mainactivity
public class MainActivity extends AppCompatActivity implements android.app.TimePickerDialog.OnTimeSetListener{
Button b1;
DialogFragment timePickerDialog1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
timePickerDialog1 = new TimePickerDialog();
timePickerDialog1.show(getSupportFragmentManager(), "timePicker");
}
});
}
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
Log.i("Dofunction", "IsDon"+i);
finish();
}
// End ;
}
class TimePickerDialog
public class TimePickerDialog extends DialogFragment implements android.app.TimePickerDialog.OnTimeSetListener{
public String AM_PM = "";
public int hourOfDay =0;
public int minute=0;
Context context;
public TimePickerDialog(){
}
@Override
public Dialog onCreateDialog(@Nullable 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);
return new android.app.TimePickerDialog(context,this , hour , minute, DateFormat.is24HourFormat(context));
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay_, int minute_){
// "11:06 PM"
if(hourOfDay_>12){
AM_PM = "PM";
hourOfDay_= hourOfDay_-12;
}else{
AM_PM = "AM";
}
hourOfDay=hourOfDay_;
minute=minute_;
}
}