Tuesday, April 8, 2014

Time between two time controls did not trigger help


public class datePick extends Activity {
private DatePicker dp1;
private TimePicker tp1;
private EditText et1;
private EditText et2;
private Handler handler = new Handler () {
@ Override
public void handleMessage (Message msg)
{
switch (msg.what) {
case 1:
int year = Integer.parseInt (msg.getData () get ("year") toString ()..);
int month = Integer.parseInt (msg.getData () get ("year") toString ()..);
int day = Integer.parseInt (msg.getData () get ("year") toString ()..);
et1.setText ("date of your choice is:" + year + "years" + (month +1) + "month" + day + "days.");
break;
case 2:
int hourOfDay = Integer.parseInt (msg.getData () get ("hourOfDay") toString ()..);
int minute = Integer.parseInt (msg.getData () get ("minute") toString ()..);
et2.setText ("your choice of time:" + hourOfDay + "hour" + minute + "points");
break;
default:
break;
}
}
};
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
init ();
}

@ Override
public boolean onCreateOptionsMenu (Menu menu) {
/ / Inflate the menu; this adds items to the action bar if it is present
.getMenuInflater () inflate (R.menu.main, menu);.
return true;
}
public void init ()
{
dp1 = (DatePicker) findViewById (R.id.dp1);
tp1 = (TimePicker) findViewById (R.id.tp1);
et1 = (EditText) findViewById (R.id.et1);
et2 = (EditText) findViewById (R.id.et2);
}
public void initDate ()
{
Calendar calendar = Calendar.getInstance ();
int year = calendar.get (Calendar.YEAR);
int month = calendar.get (Calendar.MONTH);
int day = calendar.get (Calendar.DAY_OF_MONTH);
dp1.init (year, month, day, new OnDateChangedListener () {
@ Override
public void onDateChanged (DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Message msg = new Message ();
msg.what = 1;
Bundle bundle = new Bundle ();
bundle.putString ("year", "" + year);
bundle.putString ("month", "" + monthOfYear);
bundle.putString ("day", "" + dayOfMonth);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
tp1.setOnTimeChangedListener (new OnTimeChangedListener () {
@ Override
public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {
Message msg = new Message ();
msg.what = 2;
Bundle bundle = new Bundle ();
bundle.putString ("hourOfDay", "" + hourOfDay);
bundle.putString ("minute", "" + minute);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
}
}
When I select a date two events did not trigger help
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
 public class datePick extends Activity {
private DatePicker dp1;
private TimePicker tp1;
private EditText et1;
private EditText et2;
private Handler handler = new Handler () {
@ Override
public void handleMessage (Message msg)
{
switch (msg.what) {
case 1:
int year = Integer.parseInt (msg.getData () get ("year") toString ()..);
int month = Integer.parseInt (msg.getData (). get ("month"). toString ()) ;/ / Here we get ("month"), but also with get ("year") would be wrong
int day = Integer.parseInt (msg.getData (). get ("day"). toString ()) ;/ / Here we get ("day"), but also with get ("year") would be wrong
et1.setText ("date of your choice is:" + year + "years" + (month + 1) + "month" + day + "days.");
break;
case 2:
int hourOfDay = Integer.parseInt (msg.getData () get ("hourOfDay") toString ()..);
int minute = Integer.parseInt (msg.getData () get ("minute") toString ()..);
et2.setText ("your choice of time:" + hourOfDay + "hour" + minute + "points");
break;
default:
break;
}
}
};

@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
init ();
}

public void init ()
{
dp1 = (DatePicker) findViewById (R.id.dp1);
tp1 = (TimePicker) findViewById (R.id.tp1);
et1 = (EditText) findViewById (R.id.et1);
et2 = (EditText) findViewById (R.id.et2);
initDate () ;/ / phrase you missed two Listener no registration on, so you select the date, the time is not the role.
}

public void initDate ()
{
Calendar calendar = Calendar.getInstance ();
int year = calendar.get (Calendar.YEAR);
int month = calendar.get (Calendar.MONTH);
int day = calendar.get (Calendar.DAY_OF_MONTH);
dp1.init (year, month, day, new OnDateChangedListener () {
@ Override
public void onDateChanged (DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Message msg = new Message ();
msg.what = 1;
Bundle bundle = new Bundle ();
bundle.putString ("year", "" + year);
bundle.putString ("month", "" + monthOfYear);
bundle.putString ("day", "" + dayOfMonth);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
tp1.setOnTimeChangedListener (new OnTimeChangedListener () {
@ Override
public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {
Message msg = new Message ();
msg.what = 2;
Bundle bundle = new Bundle ();
bundle.putString ("hourOfDay", "" + hourOfDay);
bundle.putString ("minute", "" + minute);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
}
}

Help you change the code, and you look at the comments.
Reply:
cited a floor tantahe reply:
 public class datePick extends Activity {
private DatePicker dp1;
private TimePicker tp1;
private EditText et1;
private EditText et2;
private Handler handler = new Handler () {
@ Override
public void handleMessage (Message msg)
{
switch (msg.what) {
case 1:
int year = Integer.parseInt (msg.getData () get ("year") toString ()..);
int month = Integer.parseInt (msg.getData (). get ("month"). toString ()) ;/ / Here we get ("month"), but also with get ("year") would be wrong
int day = Integer.parseInt (msg.getData (). get ("day"). toString ()) ;/ / Here we get ("day"), but also with get ("year") would be wrong
et1.setText ("date of your choice is:" + year + "years" + (month + 1) + "month" + day + "days.");
break;
case 2:
int hourOfDay = Integer.parseInt (msg.getData () get ("hourOfDay") toString ()..);
int minute = Integer.parseInt (msg.getData () get ("minute") toString ()..);
et2.setText ("your choice of time:" + hourOfDay + "hour" + minute + "points");
break;
default:
break;
}
}
};

@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
init ();
}

public void init ()
{
dp1 = (DatePicker) findViewById (R.id.dp1);
tp1 = (TimePicker) findViewById (R.id.tp1);
et1 = (EditText) findViewById (R.id.et1);
et2 = (EditText) findViewById (R.id.et2);
initDate () ;/ / phrase you missed two Listener no registration on, so you select the date, the time is not the role.
}

public void initDate ()
{
Calendar calendar = Calendar.getInstance ();
int year = calendar.get (Calendar.YEAR);
int month = calendar.get (Calendar.MONTH);
int day = calendar.get (Calendar.DAY_OF_MONTH);
dp1.init (year, month, day, new OnDateChangedListener () {
@ Override
public void onDateChanged (DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Message msg = new Message ();
msg.what = 1;
Bundle bundle = new Bundle ();
bundle.putString ("year", "" + year);
bundle.putString ("month", "" + monthOfYear);
bundle.putString ("day", "" + dayOfMonth);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
tp1.setOnTimeChangedListener (new OnTimeChangedListener () {
@ Override
public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {
Message msg = new Message ();
msg.what = 2;
Bundle bundle = new Bundle ();
bundle.putString ("hourOfDay", "" + hourOfDay);
bundle.putString ("minute", "" + minute);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
}
}

Help you change the code, and you look at the comments.
really here wrong but in fact there is a big mistake inverted debug guess you then complete failure
Reply:
reference to the second floor zx362168897 reply:
Quote: references to a floor tantahe reply:

 public class datePick extends Activity {
private DatePicker dp1;
private TimePicker tp1;
private EditText et1;
private EditText et2;
private Handler handler = new Handler () {
@ Override
public void handleMessage (Message msg)
{
switch (msg.what) {
case 1:
int year = Integer.parseInt (msg.getData () get ("year") toString ()..);
int month = Integer.parseInt (msg.getData (). get ("month"). toString ()) ;/ / Here we get ("month"), but also with get ("year") would be wrong
int day = Integer.parseInt (msg.getData (). get ("day"). toString ()) ;/ / Here we get ("day"), but also with get ("year") would be wrong
et1.setText ("date of your choice is:" + year + "years" + (month + 1) + "month" + day + "days.");
break;
case 2:
int hourOfDay = Integer.parseInt (msg.getData () get ("hourOfDay") toString ()..);
int minute = Integer.parseInt (msg.getData () get ("minute") toString ()..);
et2.setText ("your choice of time:" + hourOfDay + "hour" + minute + "points");
break;
default:
break;
}
}
};

@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
init ();
}

public void init ()
{
dp1 = (DatePicker) findViewById (R.id.dp1);
tp1 = (TimePicker) findViewById (R.id.tp1);
et1 = (EditText) findViewById (R.id.et1);
et2 = (EditText) findViewById (R.id.et2);
initDate () ;/ / phrase you missed two Listener no registration on, so you select the date, the time is not the role.
}

public void initDate ()
{
Calendar calendar = Calendar.getInstance ();
int year = calendar.get (Calendar.YEAR);
int month = calendar.get (Calendar.MONTH);
int day = calendar.get (Calendar.DAY_OF_MONTH);
dp1.init (year, month, day, new OnDateChangedListener () {
@ Override
public void onDateChanged (DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Message msg = new Message ();
msg.what = 1;
Bundle bundle = new Bundle ();
bundle.putString ("year", "" + year);
bundle.putString ("month", "" + monthOfYear);
bundle.putString ("day", "" + dayOfMonth);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
tp1.setOnTimeChangedListener (new OnTimeChangedListener () {
@ Override
public void onTimeChanged (TimePicker view, int hourOfDay, int minute) {
Message msg = new Message ();
msg.what = 2;
Bundle bundle = new Bundle ();
bundle.putString ("hourOfDay", "" + hourOfDay);
bundle.putString ("minute", "" + minute);
msg.setData (bundle);
handler.sendMessage (msg);
}
});
}
}

Help you change the code, and you look at the comments.
really here wrong but in fact there is a big mistake debug fails completely upside down and then you guess

debug failure mean?

No comments:

Post a Comment