From 175d76e9e4473f2da2054c14c6bfc77bbf45844b Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 21 Sep 2019 11:40:58 +0300 Subject: [PATCH] new transaction: show soft keyboard after choosing transaction date --- .../mobileledger/ui/DatePickerFragment.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/DatePickerFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/DatePickerFragment.java index abec8d6d..65794630 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/DatePickerFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/DatePickerFragment.java @@ -17,13 +17,16 @@ package net.ktnx.mobileledger.ui; +import android.app.Activity; import android.app.Dialog; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatDialogFragment; +import android.view.WindowManager; import android.widget.CalendarView; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatDialogFragment; + import net.ktnx.mobileledger.R; import java.util.Calendar; @@ -96,9 +99,13 @@ public class DatePickerFragment extends AppCompatDialogFragment } else date.setText(String.format(Locale.US, "%d/%d/%d", year, month + 1, day)); - TextView description = Objects.requireNonNull(getActivity()) - .findViewById(R.id.new_transaction_description); - description.requestFocus(); + Activity activity = getActivity(); + if (activity == null) return; + + TextView description = activity.findViewById(R.id.new_transaction_description); + boolean tookFocus = description.requestFocus(); + if (tookFocus) activity.getWindow() + .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } @Override public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, -- 2.39.5