I'm trying to get some numbers as user input from a custom dialog. I used an edittext for this purpose. when edittext is clicked the soft keyboard pops up normally, but when I'm trying to type numbers it won't show anything in edittext. only the decimal point . can be typed.
I've also tried this without limiting characters to numbers, and I've got a weird result, in this case, I can type all characters to edittext, but backspace only works on non-number characters, when I type numbers backspace won't remove them. this problem only happens in the dialog and not in activities or fragments.
what am i doing wrong?
Also i have to mention that I'm using English keyboard.
custom dialog layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_centerInParent="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
android:layout_width="@dimen/_180sdp"
android:layout_height="@dimen/_130sdp"
android:theme="@style/Theme.Trading.main_background"
app:cardCornerRadius="@dimen/_15sdp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/Theme.Trading.main_background">
<ImageView
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:background="@drawable/ic_up_down"
android:backgroundTint="@color/gray_1"
android:alpha="0.5"
android:layout_marginTop="@dimen/_17sdp"
android:layout_marginStart="@dimen/_27sdp"/>
<RelativeLayout
android:background="@drawable/border_spinner"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginStart="@dimen/_55sdp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Spinner
android:theme="@style/Theme.Trading.main_textview"
android:spinnerMode="dropdown"
android:backgroundTint="@color/purple_1"
android:id="@+id/alarm_spinner"
android:layout_width="@dimen/_90sdp"
android:layout_height="@dimen/_20sdp" />
</RelativeLayout>
<ImageView
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:background="@drawable/ic_money"
android:backgroundTint="@color/gray_1"
android:alpha="0.5"
android:layout_marginTop="@dimen/_53sdp"
android:layout_marginStart="@dimen/_25sdp"/>
<EditText
android:imeOptions="actionNext"
android:textColor="@color/gray_1"
android:inputType="numberDecimal"
android:textSize="@dimen/_10sdp"
android:layout_marginTop="@dimen/_48sdp"
android:layout_marginStart="@dimen/_55sdp"
android:layout_width="@dimen/_90sdp"
android:layout_height="wrap_content"/>
<ImageView
android:layout_width="@dimen/_20sdp"
android:layout_height="@dimen/_20sdp"
android:background="@drawable/ic_symbol"
android:backgroundTint="@color/gray_1"
android:alpha="0.5"
android:layout_marginTop="@dimen/_89sdp"
android:layout_marginStart="@dimen/_25sdp"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
and i show this dialog ti user with code below:
public void showDialog(){
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.dialog_add_alarm);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setOnKeyListener(new Dialog.OnKeyListener() {
@Override
public boolean onKey(DialogInterface arg0, int keyCode,
KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK) {
dialog.dismiss();
}
return true;
}
});
dialog.show();
}