3

I have a gridview which contains edittexts on the activity and below that there is a custom keypad as you can see in below code I added buttons to enter digits. But the problem is soft keypad is popping up whenever I click on edittexts in the gridview.

I tried putting android:windowSoftInputMode="stateHidden" in manifest file, but it doesn't even hide the soft keypad in my case. I referred lot of sources including stackoverflow without even leaving a single post. I think there is a problem in my main.xml file. Can't we hide this in childs of gridview(I know this seems silly, but this is the final doubt I am getting after trying a lot of things). Can someone please suggest where I am going wrong? It would be greatly appreciated if you test the following code with your answer and then suggest me if it works.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <FrameLayout
                android:id="@+id/fLayout1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="2"
                android:background="@drawable/background3">
        <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
                android:id="@+id/gridview"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:columnWidth="18dp"
                android:numColumns="6"
                android:verticalSpacing="0dp"
                android:horizontalSpacing="1dp"
                android:stretchMode="columnWidth"
                android:gravity="center"
                android:listSelector="@null"/>
        </FrameLayout>

        <FrameLayout
                android:id="@+id/fLayout2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="4"
                android:background="@drawable/background2">

        <TableLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/keypad"
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:stretchColumns="*">

        <TableRow>
        <Button android:id="@+id/keypad_1"
        android:text="1"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_2"
        android:text="2"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_3"
        android:text="3"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_4"   
        android:text="4"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_5"
        android:text="5"
        android:background="@drawable/custombutton">
        </Button>

        </TableRow>
        <TableRow>



        <Button android:id="@+id/keypad_6"
        android:text="6"
        android:background="@drawable/custombutton">
        </Button>

        <Button android:id="@+id/keypad_7"
        android:text="7"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_8"
        android:text="8"
        android:background="@drawable/custombutton">
        </Button>
        <Button android:id="@+id/keypad_9"
        android:text="9"
        android:background="@drawable/custombutton"> 
        </Button>

        <Button android:id="@+id/keypad_10"
        android:text="C"
        android:background="@drawable/custombutton">
        </Button>

        </TableRow>
        <TableRow>
        <Button android:id="@+id/submit"
        android:text="submit"
        android:layout_span="5"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/custombutton">

        </Button>
        </TableRow>
        </TableLayout>

        </FrameLayout>
</LinearLayout>
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Kanth
  • 6,681
  • 3
  • 29
  • 41
  • @Shrikant You can check my questions, how can I accept an answer if the given solution is not even giving hints for my problem. I dont – Kanth Sep 17 '12 at 09:07
  • If you are not getting proper answers to your question, then check if you have explained question nicely. I am sure you might have read but still I would suggest you to always read FAQs before posting a question on this website. – Shrikant Ballal Sep 17 '12 at 09:13
  • It seems like an argument to me. I would be pleased if you can ask me now, in case you have any doubts in my questions. This question is no exception. Of course I always express gratitude because at least they are trying to help solve my problem. – Kanth Sep 17 '12 at 09:17

1 Answers1

1

Have you tried adding this line in the onCreate() method?

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

OR

try what you did before in the manifest but instead of stateHidden write stateAlwaysHidden

OR

have you tried placing an onTouch listener on the EditText? If i'm not mistaken it will "consume" the touch event and the keyboard should not appear. Something like:

editText_input_field.setOnTouchListener(otl);

private OnTouchListener otl = new OnTouchListener() {
    public boolean onTouch (View v, MotionEvent event) {
            return true; // the listener has consumed the event
    }
 };

taken from here

let me know if anything works :). I'll think of some other solutions if not ...

Community
  • 1
  • 1
AndreiBogdan
  • 10,858
  • 13
  • 58
  • 106
  • Thanks for your response. Even I tried these too previously. Didn't work. Finally editText.setFocusable(false); worked, but it is not highlighting the edittext when clicked and cursor is also not visible. So, I can't use this too. Even I tried requestFocus, but didn't work. – Kanth Sep 17 '12 at 09:49
  • I tried this too previously: editText.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { editText.setFocusable(true); editText.setFocusableInTouchMode(true); return false; } }); but didn't work. Your's too now but didn't work. Now it's completely disabling edittexts. – Kanth Sep 18 '12 at 04:33
  • Thank you so much for your time. +1 for that. Please let me know if you find any other solution. – Kanth Sep 18 '12 at 04:36