I did a date chosen to have two buttons "OK" and "Cancel." I want to achieve the effect of click "Cancel" to close the pop-up dialog box, select the date and press "OK" to close the pop-up dialog box while the date is written textview of the selected date. But now no matter what I press "Cancel" or "OK", the date will be written in textview. How to solve? "Cancel" and "OK" click event associated with onDateSet what? There toast pop-up message if I write the report in onDateSet "Unfortunately, test01 has stopped." Mistake, this is why?
private DatePickerDialog.OnDateSetListener DatePickerListener = new DatePickerDialog.OnDateSetListener () {
@ Override public void onDateSet (DatePicker view, int year, int monthOfYear, int dayOfMonth) { / / TODO Auto-generated method stub textview = (TextView) findViewById (R.id.textview1); textview.setText (year + "-" + monthOfYear + "-" + dayOfMonth); } };
DatePickerDialog picker = new DatePickerDialog (MainActivity.this, DatePickerListener, iYear, iMonth, iDay); picker.setCancelable (true); picker.setCanceledOnTouchOutside (true); picker.setButton (DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Correct behavior!"); } }); picker.setButton (DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Cancel!"); } }); picker.show ();
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) -> Reply: You put textview = (TextView) findViewById (R.id.textview1); textview.setText (year + "-" + monthOfYear + "-" + dayOfMonth); into the "OK" button in Try Reply:
Click OK in the event there are no incoming year, monthOfYear, dayOfMonth these three parameters Reply:
Can onDateSet () parameter will be coming out, and then in the onClick () to handle the Reply:
You put textview = (TextView) findViewById (R.id.textview1); textview.setText (year + "-" + monthOfYear + "-" + dayOfMonth); into the "OK" button in Try
Click OK in the event there are no incoming year, monthOfYear, dayOfMonth these three parameters
Can onDateSet () parameter will be coming out, and then in the onClick () go deal
Such seemingly becomes complicated, ah, I read very simple, the effect is not the same as running-_-;; Reply: Many books online content on the Android seems to have become obsolete, people are depressed. Reply: My posts float to ~ Reply: Why is it so Reply: Code is incomplete ah! Where the assignment date, all posted Come! Reply: Sorry, did not see. You can add a boolean flag, @ Override public void onDateSet (DatePicker view, int year, int monthOfYear, int dayOfMonth) { / / TODO Auto-generated method stub if (flag) { textview = (TextView) findViewById (R.id.textview1); textview.setText (year + "-" + monthOfYear + "-" + dayOfMonth); } } picker.setButton (DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Correct behavior!"); flag = true; } }); picker.setButton (DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Cancel!"); flag = false; } });
Reply: What used book? ? I feel you write this demo problem! Reply:
sorry, did not see. You can add a boolean flag,
Thank you very much, this method you can. But this appears to me to write a vegetable, I think there should not borrow DatePickerDialog other external variables solution. . . I do not know if anyone would be standard generic approach. Reply:
with what book? ? I feel you write this demo problem!
My book is a DatePicker control, is added directly to the Activity on, rather than press a button pops up. I see the application on the phone all the pop-up thing, and then I found online the following method. new DatePickerDialog (MainActivity.this, DatePickerListener, iYear, iMonth, iDay) show ();. So when people are using the "OK" and "Cancel" buttons, and I use only one "OK" button. Later, a well-intentioned people can use the Internet to tell me setButton method to add the Cancel button. But the problem I mentioned above plus onDateSet appear after it. Reply:
What used book? ? I feel you write this demo problem!
My book is a DatePicker control, is added directly to the Activity on, rather than press a button pops up. I see the application on the phone all the pop-up thing, and then I found online the following method. new DatePickerDialog (MainActivity.this, DatePickerListener, iYear, iMonth, iDay) show ();. So when people are using the "OK" and "Cancel" buttons, and I use only one "OK" button. Later, a well-intentioned people can use the Internet to tell me setButton method to add the Cancel button. But the problem I mentioned above plus onDateSet appear after it.
I ask you to easily put your demo code directly sent for me, I can help you tune the next try! !
Reply: @ Override public void onDateSet (DatePicker view, int year, int monthOfYear, int dayOfMonth) {
I understand this approach, DatePicker is selected the default value, so whether you're OK or Cancel, year, month, and day will be filled in textview in, because you fill in the contents of this method in the.
If the landlord to solve this problem, please share, thank Ha! Reply:
ask you to easily put your demo code directly sent for me, I can help you tune the next try! !
final Calendar objTime = Calendar.getInstance (); int iYear = objTime.get (Calendar.YEAR); int iMonth = objTime.get (Calendar.MONTH); int iDay = objTime.get (Calendar.DAY_OF_MONTH);
/ / New DatePickerDialog (MainActivity.this, DatePickerListener, iYear, iMonth, iDay) show ();. DatePickerDialog picker = new DatePickerDialog (MainActivity.this, DatePickerListener, iYear, iMonth, iDay); picker.setCancelable (true); picker.setCanceledOnTouchOutside (true); picker.setButton (DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Correct behavior!"); } }); picker.setButton (DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Cancel!"); } }); picker.show ();
}
@ 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; }
}
Reply:
@ Override public void onDateSet (DatePicker view, int year, int monthOfYear, int dayOfMonth) {
I understand this approach, DatePicker is selected the default value, so whether you're OK or Cancel, year, month, and day will be filled in textview in, because you fill in the contents of this method in the.
If the landlord to solve this problem, please share, thank Ha!
Some people say that the Internet is that no matter the point "OK" or "Cancel" will tune onDateSet methods.
Reply:
I ask you to easily put your demo code directly sent for me, I can help you tune the next try! !
final Calendar objTime = Calendar.getInstance (); int iYear = objTime.get (Calendar.YEAR); int iMonth = objTime.get (Calendar.MONTH); int iDay = objTime.get (Calendar.DAY_OF_MONTH);
/ / New DatePickerDialog (MainActivity.this, DatePickerListener, iYear, iMonth, iDay) show ();. DatePickerDialog picker = new DatePickerDialog (MainActivity.this, DatePickerListener, iYear, iMonth, iDay); picker.setCancelable (true); picker.setCanceledOnTouchOutside (true); picker.setButton (DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Correct behavior!"); } }); picker.setButton (DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener () { @ Override public void onClick (DialogInterface dialog, int which) { Log.d ("Picker", "Cancel!"); } }); picker.show ();
}
@ 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; }
}
Ha just come back, I see! ! ! Reply:
@ Override public void onDateSet (DatePicker view, int year, int monthOfYear, int dayOfMonth) {
I understand this approach, DatePicker is selected the default value, so whether you're OK or Cancel, year, month, and day will be filled in textview in, because you fill in the contents of this method in the.
If the landlord to solve this problem, please share, thank Ha!
Some people say that the Internet is that no matter the point "OK" or "Cancel" will tune onDateSet methods.
This is a bug 4.1 of Reply: Hello Ha, that that iYear Toast is because you are int type, you add (+ "") can be Then I saw that DatePickerDialog source, the feeling is no problem, then I changed the kinds of ideas tried, found it was so OnDateSet you that you are actually triggered this "dialog" closed, it was going to change the date of recognition rather than change in your "date control, date time value", so, in fact, there is a question, you shut off the dialog, no matter in what way off (for example: press the "back" button, "or touch the screen to another location," or press the "cancle"), certainly will trigger this event, and will After you set the button's onclick own execution finished execution, so you can only write that which led to "the view layer view" things that onDateSet inside, you use this stuff, although convenient, but too inflexible your own layout casual look, put a datePicker and then write their own two button, it will not know how much useful than this! ! ! Reply: dataset will definitely callback method. The idea itself of this problem is a problem, sometimes the result is the main Reply: toast crash, 19 # positive solution! Reply:
Hello Ha, that that iYear Toast is because you are int type, you add (+ "") on can Then I saw that DatePickerDialog source, the feeling is no problem, then I changed the kinds of ideas tried, found it was so OnDateSet you that you are actually triggered this "dialog" closed, it was going to change the date of recognition rather than change in your "date control, date time value", so, in fact, there is a question, you shut off the dialog, no matter in what way off (for example: press the "back" button, "or touch the screen to another location," or press the "cancle"), certainly will trigger this event, and will After you set the button's onclick own execution finished execution, so you can only write that which led to "the view layer view" things that onDateSet inside, you use this stuff, although convenient, but too inflexible your own layout casual look, put a datePicker and then write their own two button, it will not know how much useful than this! ! !
No comments:
Post a Comment