hide virtual keyboar

4 views
Skip to first unread message

Siddharth Verma

unread,
Mar 14, 2011, 5:06:31 AM3/14/11
to bpgc-androi...@googlegroups.com
for ppl who were facing this problem of hiding the virtual keyboard after you're done using it, here' the code to do it:

public void onClick(View v) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
...
}
while copy pasting, take care of v.getWindowToken()
here v is my View name

Siddharth Verma

unread,
Mar 14, 2011, 5:10:56 AM3/14/11
to bpgc-androi...@googlegroups.com
guys can anyone help me with this:
i want to make the user write a phone number in the edittext box... i have given the name of the EditText box as PhoneNo1... so i expect that when the user touches this box, "Phoneno1" will erase on its own and the box will be clear and ready for the user to straight away enter his phone number...
rite now this is not happening

Alok Sharma

unread,
Mar 14, 2011, 5:55:00 AM3/14/11
to bpgc-androi...@googlegroups.com
umm...u cud use the OnClick or the OnFocus or any other such method and give PhoneNo1.settext as a blank (" ")....might help...

Emaad Ahmed Manzoor

unread,
Mar 14, 2011, 6:01:28 AM3/14/11
to bpgc-androi...@googlegroups.com
This function is built in. The best way to do this is from the XML file.

Add the attribute android:hint="@string/search_hint" to your EditText
in the XML file, replacing "@string/search_hint" with whatever text
you need.

I've attached some screenshots of it in action.

--
Emaad Ahmed Manzoor,
Third Year Undergraduate,
BITS - Pilani, KK Birla Goa Campus.
halfclosed.wordpress.com

two.png
one.png

Alok Sharma

unread,
Mar 14, 2011, 6:02:43 AM3/14/11
to bpgc-androi...@googlegroups.com
ohh..nice!

Mohit Yadav

unread,
Mar 14, 2011, 6:04:40 AM3/14/11
to bpgc-androi...@googlegroups.com
that's nice..!!

Siddharth Verma

unread,
Mar 14, 2011, 6:07:54 AM3/14/11
to bpgc-androi...@googlegroups.com
wow!!!
gr8 help emaad!!!

On Mon, Mar 14, 2011 at 3:31 PM, Emaad Ahmed Manzoor <emaadm...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages