0

I have a grid view and want to show a keyboard when the user clicks on a cell. The input of the keyboard will then appear in the cell. I've tried the code below which I got from Android: show soft keyboard automatically when focus is on an EditText and other similar questions. I can't get the keyboard to show up, though.

Any ideas on this?

 gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(gridView, InputMethodManager.SHOW_IMPLICIT);
        }
    });

I have tried InputMethodManager.SHOW_FORCED but that didn't help either.

Thanks

EDIT

The cell layout for the grid is below. I changed it to an EditText but still no keyboard. Having it as EditText doesn't look too good for me from a UI point of view. Ideally, I was the TextView and then perhaps when the user clicks it becomes an EditText so the user can enter something.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="5dp" >

<EditText
        android:id="@+id/grid_item_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/celllabel"
        android:textSize="15px" >
</EditText>

My idea is that it stays as a TextView. The keyboard opens and when the user clicks one letter the keyboard closes and that a letter appears in the GridCell. Is my idea possible?

Thanks

Community
  • 1
  • 1
RNJ
  • 14,308
  • 16
  • 73
  • 125

1 Answers1

1

One suggestion:

  1. Create a custom EditText, you can hide the cursor if you want (make it looks like a TextView).
  2. Optimize your cell layout by removing the LinearLayout

Code:

<?xml version="1.0" encoding="utf-8"?>
<YourCustomEditText xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/grid_item_label"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@+id/celllabel"
        android:maxLength="1"
        android:textSize="15px" >
</YourCustomEditText>
  1. Use TextWatcher or focus interface to control the show/hide of the keyboard.

Hope this help!

Community
  • 1
  • 1
T D Nguyen
  • 5,353
  • 4
  • 38
  • 57
  • Thanks for the help @tung-d-nguyen I will start playing now. One immediate question is why do you think I need to have a custom EditText? Can I not do everything with just the standard EditText? – RNJ May 10 '16 at 08:19
  • @RNJ it is OK to use the default one. – T D Nguyen May 11 '16 at 00:45