Activity with visible soft keyboard

I saw some similar questions here, but did not find what I was really looking for. I need to create a simple activity when the user needs to enter a number and return it to the main action. The layout should contain only the editing text in the upper half of the screen and the soft keyboard in the lower half of the screen. The action should complete when the Done key is pressed on the keyboard. Understand any links or snippets of code to help solve this problem.

+4
source share
1 answer

I recommend that you use Custom Dialog to do this.

The fact is that you want the keyboard to interact and return when a number is pressed, right?

If you need an example, you can create a dialog action like:

public class Keypad extends Dialog protected static final String TAG = "Keypad" ; private final View keys[] = new View[9]; private View keypad; private int tecla = 0; 

Then set this content on creation:

 setContentView(R.layout.keypad); findViews(); setListeners(); 

Find species will be something like this:

 keypad = findViewById(R.id.keypad); keys[0] = findViewById(R.id.keypad_1); ... 

And the XML dialog should have a table:

 <TableRow> <Button android:id="@+id/keypad_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="keypadClick" android:text="keypadClick"></Button> <Button android:id="@+id/keypad_2" android:text="2" > </Button> <Button android:id="@+id/keypad_3" android:text="3" > </Button> </TableRow> ... Etc 

So, when you start the dialogue, you will see a menu with 9 numbers (in my case), which are fired when 1 of them is clicked, and cancel the dialogue (return to the point where the throw was)

I hope this helps!

+1
source

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


All Articles