Instead of using button use an edit text and change the background of the edittext to make it look like a button
How to change the Button text with the android keyboard?
-
26-06-2023 - |
Frage
I created a button in my xml (normal button) with text set to "0". I attached an OnClickListner to it, and I got the keyboard to show using this code:
public void Measure(View paramView) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
Now I want the text in the button to change when I write something using the popped up keyboard. I want to fill it with numbers - example 13.45.
I don't want to change the button to an editText.
Anyone got an idea how to do this? Can anyone help? Thanks in advance for all the replies.
Lösung
Andere Tipps
try this please:
final Button mbutton=(Button)android.findViewById(R.id.m_button_id);
mbutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
mbutton.setText(12+"");
//or mbutton.setText("12");
}
});
There is a way to do this through XML by specifying a button's android:inputType="text" like so
in MainActivity.java:
final Button editableButton = findViewById(R.id.editableButton);
in activity_main.xml:
<Button
android:id="@+id/editableButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="Button1" />
I have not figured out how to do this by Java alone. Using
button.setInputType(InputType.TYPE_CLASS_TEXT)
does not work, even though it feels like it should =(