且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替代NumberPicker的API 8

更新时间:2022-01-17 22:16:56

最简单的(也最丑陋的),将与inputtype号码一个EditText。

The easiest (but also most ugly) would be an edittext with inputtype number.

但要做出从头心不是一个数字选择器难。

But making a number picker from scratch isnt that hard.

您只需要一个TextView这需要一个变量为文本。添加+和 - 按钮,增加/减少变量并调用Textview.setText(可变)

You just need a Textview which takes a variable as text. Add a + and - button which increment/decrement the variable and call Textview.setText(variable)

counter = 0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
display = (TextView) findViewById(R.id.tvDisplay);

add.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    counter++;
    display.setText( "" + counter);
    }
});

sub.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    counter--;
    display.setText( "" + counter);
    }
});

}

在XML中只需添加2个按钮id为BADD和bSub和ID tvDisplay一个TextView并安排他们像你想

in xml just add 2 buttons with id bAdd and bSub and a textview with id tvDisplay and arrange them like you want