Android中角色的选择器 [英] Picker for characters in android

查看:94
本文介绍了Android中角色的选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android开发的初学者,所以我想问你,如何为字母组合创建选择器?

I'm a beginner in the android development, so I would like to ask you , How to create picker for letters of alphabet ?

推荐答案

我最近试图弄清楚这一点,您可以使用NumberPicker小部件来实现.

I was recently trying to figure this out, and you can do it by using the NumberPicker widget.

在您的XML中定义您的号码选择器

In your XML define your number picker

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

          <NumberPicker
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/NumberPicker"/>

 </LinearLayout>

然后在您的onCreate方法中创建一个NumberPicker并强制转换XML布局,然后使用NumberPicker方法设置数据.

Then in your onCreate method create a NumberPicker and cast the XML layout, then set your data using the NumberPicker methods.

下面使用的方法创建要在选择器中显示的项目数组.最小值和最大值创建数字范围.如果范围与数组中的项目数不同,则它将不会运行.因此,如果其完整字母为0和25. setDisplayedValues方法会使用数组中的相应值(0、1、2等)覆盖您定义的数字

The methods used below create the array of items to be displayed in the picker. The min and max value create the range for numbers. If the range isn't the same number of items in your array it won't run. So if its the full alphabet do 0 and 25. The setDisplayedValues method overrides the numbers you defined with the corresponding values in the array (0, 1, 2 etc)

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout);

    NumberPicker NumberPicker = (NumberPicker) findViewById(R.id.NumberPicker);
            String[] alphabet = {"A","B","C","D","E","F","G"}; //etc
            NumberPicker.setMaxValue(0); 
            NumberPicker.setMaxValue(6);
            NumberPicker.setDisplayedValues(alphabet);
}

我知道这个问题是3年前的....哦,好吧...希望您还没有陷入困境,也许这会帮助其他人.

I know this question was from 3 years ago....oh well...hope you're still not stuck and maybe this will help someone else out.

也是这个 将NumberPicker小部件与字符串一起使用

这篇关于Android中角色的选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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