NumberPicker Alternative for API 8

Possible duplicate:
How to implement NumberPicker in Android API 7?

I need to select a small integer in the range from 0 to 12. The space in my user interface for this is limited and should be wider than it is high. Is there a widget in API 8 that will allow me to do this?

EDIT: Duplicate previous SO question. I saw a closely related question, but A) he did not limit the "landscape orientation" and B). The proposal to copy the code from api 11 was not accompanied by an explanation of exactly how to do this.

+4
source share
2 answers

The simplest (but also the ugliest) will be the edittext with the input number.

But making a number collector from scratch is not so difficult.

You just need a Textview that takes a variable as text. Add a + and - button, which increase / decrease 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); } }); } 

in xml just add 2 buttons with id bAdd and bSub and text image with id tvDisplay and arrange them as you want

+8
source

Try a look at Custom Number Picker . I would start from this and simply change the layout of the control so that it is oriented horizontally.

Another option is to find the source code for Android 2.3.4 NumberPicker and NumberPickerButton and copy it. It will also require copying the resources needed for these controls. Again, you will need to rearrange the buttons so that they are horizontally oriented.

I would not recommend using NumberPicker from API 11 or higher. You will find that there are many dependencies on new classes that are not available to you with API 8.

+1
source

Source: https://habr.com/ru/post/908005/


All Articles