Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3.  
  4. TextView topText;
  5. TextView topNumber;
  6. NumberPicker numberPicker;
  7. View topView;
  8. View bottomView;
  9. int enterNumber = 1;
  10. boolean isFullView;
  11.  
  12. @Override
  13. protected void onCreate(final Bundle savedInstanceState) {
  14. super.onCreate(savedInstanceState);
  15. setContentView(R.layout.activity_main);
  16.  
  17. topText = (TextView) findViewById(R.id.topText);
  18. topNumber = (TextView) findViewById(R.id.topNumber);
  19. numberPicker = (NumberPicker) findViewById(R.id.numberPicker);
  20. topView = findViewById(R.id.topView);
  21. bottomView = findViewById(R.id.bottomView);
  22.  
  23. topText.setText("Some Text");
  24. topNumber.setText(String.valueOf(enterNumber));
  25.  
  26. numberPicker.setMinValue(0);
  27. numberPicker.setMaxValue(9);
  28. numberPicker.setValue(enterNumber);
  29.  
  30. topView.setOnClickListener(new View.OnClickListener() {
  31. @Override
  32. public void onClick(View v) {
  33. bottomView.setVisibility(isFullView ? View.VISIBLE : View.GONE);
  34. isFullView = !isFullView;
  35. topNumber.setText(String.valueOf(enterNumber));
  36.  
  37. }
  38. });
  39.  
  40. numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
  41. @Override
  42. public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
  43.  
  44. enterNumber = newVal;
  45.  
  46. }
  47. });
  48. }
  49. }
  50.  
  51. <LinearLayout
  52. xmlns:android="http://schemas.android.com/apk/res/android"
  53. android:layout_width="wrap_content"
  54. android:layout_height="match_parent"
  55. android:orientation="vertical">
  56.  
  57.  
  58. <LinearLayout
  59. android:orientation="vertical"
  60. android:layout_width="match_parent"
  61. android:layout_height="wrap_content"
  62. android:id="@+id/topView">
  63.  
  64. <TextView
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:id="@+id/topText"
  68. android:layout_gravity="center_horizontal"
  69. android:padding="6dp" />
  70.  
  71. <TextView
  72. android:layout_width="wrap_content"
  73. android:layout_height="wrap_content"
  74. android:id="@+id/topNumber"
  75. android:layout_gravity="center_horizontal"
  76. android:padding="6dp" />
  77. </LinearLayout>
  78.  
  79. <LinearLayout
  80. android:orientation="vertical"
  81. android:layout_width="match_parent"
  82. android:layout_height="wrap_content"
  83. android:id="@+id/bottomView"
  84. android:visibility="gone">
  85.  
  86. <NumberPicker
  87. android:layout_width="wrap_content"
  88. android:layout_height="wrap_content"
  89. android:id="@+id/numberPicker"
  90. android:layout_gravity="center_horizontal" />
  91. </LinearLayout>
  92. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement