Guest User

Untitled

a guest
Oct 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. public void showNumberPickerDialog( String title, int value, String unit)
  2. {
  3. final Dialog d = new Dialog(getActivity());
  4. d.setTitle(title);
  5. d.setContentView(R.layout.dialog_numberpick);
  6. Button btnOk = (Button) d.findViewById(R.id.btn_ok);
  7. Button btnCancel = (Button) d.findViewById(R.id.btn_cancel);
  8.  
  9. int iH = (value / 100) % 100;
  10. int iZ = (value / 10) % 10;
  11. int iE = value % 10;
  12.  
  13. final NumberPicker np0 = (NumberPicker) d.findViewById(R.id.numberPicker0);
  14. final NumberPicker np1 = (NumberPicker) d.findViewById(R.id.numberPicker1);
  15. final NumberPicker np2 = (NumberPicker) d.findViewById(R.id.numberPicker2);
  16. final TextView unt = (TextView) d.findViewById(R.id.unit);
  17. np0.setMaxValue(9);
  18. np0.setMinValue(0);
  19. np1.setMaxValue(9);
  20. np1.setMinValue(0);
  21. np2.setMaxValue(9);
  22. np2.setMinValue(0);
  23.  
  24. np0.setValue(iE);
  25. np1.setValue(iZ);
  26. np2.setValue(iH);
  27. unt.setText(unit);
  28.  
  29. np0.setWrapSelectorWheel(true);
  30. np1.setWrapSelectorWheel(true);
  31. np2.setWrapSelectorWheel(true);
  32.  
  33. btnOk.setOnClickListener(new View.OnClickListener()
  34. {
  35. @Override
  36. public void onClick(View v) {
  37. Log.d(LOG_TAG, "btnOK click.");
  38. int aVal = np0.getValue() + (np1.getValue()*10) + (np2.getValue()*100);
  39.  
  40. //do something with aVal
  41.  
  42. d.dismiss();
  43. }
  44. });
  45.  
  46. btnCancel.setOnClickListener(new View.OnClickListener()
  47. {
  48. @Override
  49. public void onClick(View v) {
  50. Log.d(LOG_TAG, "btnCancel click.");
  51. d.dismiss();
  52. }
  53. });
  54.  
  55. d.show();
  56. }
  57.  
  58.  
  59. // Dialog DoEdit
  60.  
  61. public void showMyEditDialog( DsFi f )
  62. {
  63. final Dialog d = new Dialog(this, R.style.Dlg);
  64. d.setTitle("My Title");
  65. d.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  66. d.setContentView(R.layout.activity_dlg_edit);
  67.  
  68. Button btnClose = (Button) d.findViewById(R.id.dfe_btn_close);
  69.  
  70. TextView tvStartNum = (TextView) d.findViewById(R.id.dfe_txt_startnum);
  71. TextView tvEndNum = (TextView) d.findViewById(R.id.dfe_txt_endnum);
  72. TextView tvDuration = (TextView) d.findViewById(R.id.dfe_txt_duration);
  73.  
  74. tvStartNum.setText(String.format("%d", f.getStartNum()) );
  75. tvEndNum.setText(String.format("%d", f.getEndNum()) );
  76. tvDuration.setText(String.format("%d", f.getDuration()) );
  77.  
  78. btnClose.setOnClickListener(new View.OnClickListener()
  79. {
  80. @Override
  81. public void onClick(View v) {
  82. Log.d(LOG_TAG, "btnReload click.");
  83. }
  84. });
  85.  
  86. // this is fiction, but thats how i want to use my MyNumPickerDialog class.
  87. final MyNumPickerDialog dlgNP = new MyNumPickerDialog(this, new MyNumPickerDialog.OnNumSetListener() {
  88. public void onNumSet(NumPickerDialog view, int num) {
  89. tvStartNum.setText(String.format("%d", num()) );
  90. }
  91. };
  92. // end fiction
  93.  
  94. tvStartNum.setOnClickListener(new View.OnClickListener() {
  95. @Override
  96. public void onClick(View vi) {
  97. String sNum = tvStartNum.getText().toString();
  98. int n = Integer.parseInt(sNum);
  99. // fiction ...
  100. dlgNP.updateNum(n);
  101. dlgNP.show();
  102. }
  103. });
  104.  
  105.  
  106. d.show();
  107. }
Add Comment
Please, Sign In to add comment