安卓學習-介面-ui-NumberPicker

來源:互聯網
上載者:User

標籤:android   style   blog   http   color   os   java   ar   2014   

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="${relativePackage}.${activityClass}" >    <NumberPicker        android:id="@+id/numberPicker1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true" />    <TextView        android:id="@+id/textView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentLeft="true"        android:layout_below="@+id/numberPicker1"        android:layout_marginLeft="17dp"        android:text="數值:"        android:textAppearance="?android:attr/textAppearanceLarge" />    <Button        android:id="@+id/button1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentTop="true"        android:layout_marginTop="18dp"        android:layout_toRightOf="@+id/textView1"        android:text="設定成50" /></RelativeLayout>
View Code

MainActivity.java

public class MainActivity extends Activity {    NumberPicker numberPicker;    Button button1;        @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                numberPicker=(NumberPicker)findViewById(R.id.numberPicker1);        numberPicker.setMaxValue(100);        numberPicker.setMinValue(1);        numberPicker.setOnValueChangedListener(new OnValueChangeListener() {                        @Override            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {                TextView textView1=(TextView)findViewById(R.id.textView1);                textView1.setText("原【"+oldVal+"】"+"改成【"+newVal+"】");            }        });                button1=(Button)findViewById(R.id.button1);        button1.setOnClickListener(new OnClickListener() {            public void onClick(View v) {                //這裡居然不會觸發setOnValueChangedListener,算是bug嗎                numberPicker.setValue(50);                            }        });    }}
View Code

 

安卓學習-介面-ui-NumberPicker

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.