2012-09-17 201 views
3

我有一个gridview包含活动和下面的edittexts有一个自定义键盘,你可以在下面的代码中看到我添加了按钮来输入数字。但问题是,当我点击gridview中的edittext时,软键盘弹出。隐藏软键盘问题

我试着把android:windowSoftInputMode="stateHidden"放在清单文件中,但它甚至没有隐藏我的情况下的软键盘。我提到很多源码,包括stackoverflow,甚至没有留下任何一篇文章。我认为我的main.xml文件存在问题。我们不能把它隐藏在gridview的child里面(我知道这看起来很愚蠢,但这是我在尝试了很多事情之后所得到的最终怀疑)。有人可以建议我去哪里错了吗?如果你用你的答案测试下面的代码,然后建议我它是否有效,将不胜感激。

<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> 
+0

@Shrikant你可以检查我的问题,如果给定的解决方案甚至不提供我的问题提示,我怎么可以接受答案。我不 – Kanth

+0

如果你没有得到你的问题的正确答案,然后检查你是否很好地解释了问题。我相信你可能已经阅读过,但我仍然建议你在发布本网站上的问题之前总是阅读常见问题解答。 – Shrikant

+0

这似乎是对我的一个论据。如果你现在可以问我,我会很高兴,如果你对我的问题有任何疑问。这个问题也不例外。当然,我总是表示感谢,因为至少他们正试图帮助解决我的问题。 – Kanth

回答

1

您是否尝试过在onCreate()方法中添加此行?

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

OR

尝试你在清单之前做了什么,但不是stateHiddenstateAlwaysHidden

OR

你试图将一个onTouch听众对EditText?如果我没有弄错它会“消耗”触摸事件,并且键盘不应该出现。 喜欢的东西:

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 
    } 
}; 

here

采取让我知道,如果有什么作品:)。我会考虑一些其他的解决方案,如果不是...

+0

感谢您的回复。即使我也尝试过这些。没有工作。最后editText.setFocusable(false);工作,但它没有突出显示edittext点击和光标也不可见。所以,我也不能使用它。即使我尝试了requestFocus,但没有奏效。 – Kanth

+0

我想这也是以前:editText.setOnTouchListener(新View.OnTouchListener(){ \t 公共布尔onTouch(视图V,MotionEvent事件){ editText.setFocusable(真); editText.setFocusableInTouchMode(真); return false; } });但没有工作。你的太了,但没有工作。现在它完全禁用了edittexts。 – Kanth

+0

非常感谢你的时间。 +1。请让我知道,如果你找到任何其他解决方案。 – Kanth