Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Soft keyboard showing automatically when focus is changed (OnStart event)

I am developing for a tablet using Android 2.2.

I have a form which I am using for new and editable instances. When editable, I want to stop the user from editing certain fields. I manage this in my onStart-event, setting the txt.setFocusableInTouchMode(false). This forces the focus to the next focusable EditText in my form (which is great), but when running, the soft keyboard automatically appears for the EditText with the focus. Anybody know how to stop this?

Here's the code (called in the onStart event):

private void PopulateFields(){     TextView txtTitle = (TextView) this.findViewById(R.id.txtEquipmentEditTitle);     AutoCompleteTextView txtMake = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditMake);     AutoCompleteTextView txtModel = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditModel);     EditText txtDesc = (EditText) this.findViewById(R.id.txtEquipmentEditDesc);     TextView txtDeptKey = (TextView) this.findViewById(R.id.txtEquipmentEditDeptKey);     EditText txtSerial = (EditText) this.findViewById(R.id.txtEquipmentEditSerialNo);     EditText txtBarCode = (EditText) this.findViewById(R.id.txtEquipmentEditBarCode);      txtTitle.setText("Edit Equipment");     txtMake.setText(make);     txtModel.setText(model);     txtDesc.setText(desc);     txtDeptKey.setText(Integer.toString(deptKey));     txtSerial.setText(serial);     txtBarCode.setText(barCode);     txtMake.setEnabled(false);     txtModel.setEnabled(false);     txtDesc.setEnabled(false);     txtMake.setClickable(false);     txtMake.setFocusableInTouchMode(false);     txtModel.setFocusableInTouchMode(false);     txtDesc.setFocusableInTouchMode(false);     txtMake.setFocusable(false);     txtModel.setFocusable(false);     txtDesc.setFocusable(false); } 
like image 938
Rune Borgen Avatar asked Mar 07 '11 15:03

Rune Borgen


1 Answers

Maybe this will help you:

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

Put this method in the onCreate() method of your activity when the activity is first created or called.

like image 97
MobileCushion Avatar answered Sep 27 '22 20:09

MobileCushion