Miya
Miya

Reputation: 203

problem with virtual keyboard in android

my actvity has 2 views. That means I am using 2 .xml files within one java class.

       first_view.xml
       second_view.xml

First view (first_view.xml) contains one EditText and one save button. when I click the EditText, the virtual keyboard is displayed on the view, and I can enter a value there. In onClick() of save button, i want to display the second view. (that means the details of the enterd value).

So i use 'setContentView(R.layout.second_view);' on the onClick() of save button.

My problem is the second view is coming properly, but the virtual keyboard is still displayed on the view. I use LinearLayout in second view, and set its height and width as "fill_parent". but I can't solve the problem.

I hope you understand the question.. Please help me... Thank you...

Upvotes: 0

Views: 570

Answers (2)

Sebastian Roth
Sebastian Roth

Reputation: 11537

I think you are not really supposed to call setContentView() to change the UI after it has been loaded & the activity created. If you intend to change the UI, consider a LayoutInflater: http://developer.android.com/reference/android/view/LayoutInflater.html

How about you add another Activity, and simple call it? This will save you a lot of trouble in the long term, like freeing up memory and so on. If you intend to replace the current activity with the new one, consider a call to finish() before you call the new one.

Upvotes: 1

100rabh
100rabh

Reputation: 6186

@Miya I suggest you to have a look @ this thread Close/hide the Android Soft Keyboard & use this

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

& you are done!

Upvotes: 0

Related Questions