-1

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

BenMorel
  • 30,280
  • 40
  • 163
  • 285
Dev
  • 199
  • 1
  • 3
  • 10
  • 2
    "picker of letters of alphabet" I have no idea what you're talking about. The keyboard? – Jason Robinson Aug 09 '11 at 17:27
  • Hi, I mean a picker contains characters from A TO Z – Dev Aug 09 '11 at 17:32
  • like Time and Date picker , but i want to create my own picker only for Characters from A to Z. – Dev Aug 09 '11 at 17:35
  • can you show a picture or something of what you're talking about? I think we're lost in translation. – Jason Robinson Aug 09 '11 at 17:37
  • http://imageshack.us/photo/my-images/94/34689541.png – Dev Aug 09 '11 at 17:51
  • like this image : http://imageshack.us/photo/my-images/94/34689541.png but I want to show characters instead of numbers. Thanks for your cooperation – Dev Aug 09 '11 at 17:52
  • So you want a box with up and down arrows populated with the alphabet...so starts at "A" and pressing down would select "B" and so forth? – Jason Robinson Aug 09 '11 at 17:53
  • yes yes , you get what I mean . – Dev Aug 09 '11 at 17:55
  • You could display a char in an TextView, then use buttons to setText to char++ or char--. I'll explain more in an answer, I can't see the image right now though. – Rob Aug 09 '11 at 18:25

3 Answers3

7

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

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>

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

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);
}

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.

also this Using NumberPicker Widget with Strings

Community
  • 1
  • 1
CharlesCates
  • 91
  • 1
  • 7
1

I think you want a Spinner. You should refer to this guide for how to make one.

Brian
  • 7,457
  • 15
  • 61
  • 103
0

If you don't want to use a spinner and would, for some reason, prefer to have the user click through each letter, you could set it up something like this:

TextView txt = (EditText)findViewById(R.id.pickertxt);
Button next = (Button)findViewById(R.id.nextbtn);
Button prev = (Button)findViewById(R.id.prevbtn);

char picker = 'a';
txt.setText(picker);

next.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        picker++;
        txt.setText(picker);
    }
});

prev.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        picker--;
        txt.setText(picker);
    }
});

Although using a spinner would probably be preferred (it's more like a dropdown where you can select the value from a list, rather than clicking through) or if you're doing A-Z, why not just an EditText that lets a user type it in?

Rob
  • 2,701
  • 5
  • 20
  • 34