Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. public void addEntry(View view) {
  2. final Dialog d = new Dialog(this);
  3. d.setContentView(R.layout.dialog);
  4. d.setTitle("Add Entry");
  5. d.setCancelable(true);
  6. d.show();
  7.  
  8. ...
  9.  
  10. chooseDate.setOnClickListener(new View.OnClickListener() {
  11.  
  12. @Override
  13. public void onClick(View v) {
  14. String str = selectDate();
  15. date.setText(str);
  16. }
  17. });
  18. }
  19.  
  20. public String selectDate(){
  21.  
  22. final Dialog datePicker = new Dialog(this);
  23. datePicker.setContentView(R.layout.choose_date);
  24. datePicker.setTitle("Choose Date...");
  25. datePicker.setCancelable(true);
  26. datePicker.show();
  27.  
  28. Button selectFinalDate = (Button) datePicker.findViewById(R.id.selectDate);
  29. final DatePicker dp = (DatePicker) datePicker.findViewById(R.id.datePicker1);
  30.  
  31. selectFinalDate.setOnClickListener(new View.OnClickListener() {
  32. @Override
  33. public void onClick(View v) {
  34. strDateTime = (dp.getMonth() + 1) + "/" + dp.getDayOfMonth() + "/" + dp.getYear();
  35. datePicker.dismiss();
  36. }
  37. });
  38. return strDateTime;
  39. };
  40.  
  41. ...
  42. date.setText(str);
  43. view.invalidate(); // the view that you are showing in the dialog
  44. ...
  45.  
  46. /**
  47. * global variable for your dialog view
  48. */
  49. View view =null;
  50.  
  51. // in your addEntry(View view)
  52. ...
  53. Dialog d = new Dialog(this);
  54. view = LayoutInflater.from(this).inflate(R.layout.dialog, null);
  55. d.setContentView(view);
  56. ...
  57.  
  58. // selectDate()
  59. ...
  60. date.setText(str);
  61. view.invalidate(); // the view that you are showing in the dialog
  62. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement