Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- TextView topText;
- TextView topNumber;
- NumberPicker numberPicker;
- View topView;
- View bottomView;
- int enterNumber = 1;
- boolean isFullView;
- @Override
- protected void onCreate(final Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- topText = (TextView) findViewById(R.id.topText);
- topNumber = (TextView) findViewById(R.id.topNumber);
- numberPicker = (NumberPicker) findViewById(R.id.numberPicker);
- topView = findViewById(R.id.topView);
- bottomView = findViewById(R.id.bottomView);
- topText.setText("Some Text");
- topNumber.setText(String.valueOf(enterNumber));
- numberPicker.setMinValue(0);
- numberPicker.setMaxValue(9);
- numberPicker.setValue(enterNumber);
- topView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- bottomView.setVisibility(isFullView ? View.VISIBLE : View.GONE);
- isFullView = !isFullView;
- topNumber.setText(String.valueOf(enterNumber));
- }
- });
- numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
- @Override
- public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
- enterNumber = newVal;
- }
- });
- }
- }
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:orientation="vertical">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/topView">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/topText"
- android:layout_gravity="center_horizontal"
- android:padding="6dp" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/topNumber"
- android:layout_gravity="center_horizontal"
- android:padding="6dp" />
- </LinearLayout>
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/bottomView"
- android:visibility="gone">
- <NumberPicker
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/numberPicker"
- android:layout_gravity="center_horizontal" />
- </LinearLayout>
- </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement