替代NumberPicker的API 8 [英] Alternative to NumberPicker for API 8

查看:128
本文介绍了替代NumberPicker的API 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/9205060/how-would-one-implement-a-numberpicker-in-android-api-7">How一会实现Android的API一个NumberPicker 7?

我需要选择一个小整数范围为0到12,我的用户界面做到这一点的空间受到限制,必须是宽度大于高度。是否有API 8提供一个小工具,可以让我做到这一点?

I need to pick a small integer in the range 0 to 12. The space in my UI to do this is restricted and must be wider than it is tall. Is there a widget available in API 8 that will allow me to do this?

编辑:重新的previous可能出现的重复SO问题。我看到了一个密切相关的问题,但一)它并没有横向的限制和b)建议:code可从API 11拷贝不跟进究竟如何做到这一点的解释。

Re possible duplication of previous SO question. I saw a closely related question, but A) it made no "landscape orientation" restriction and B) A suggestion that code could be copied from api 11 was not followed up with an explanation of exactly how to do it.

推荐答案

最简单的(也最丑陋的),将与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

这篇关于替代NumberPicker的API 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆