Recently encountered a question about the Android soft keyboard. Each item in the ListView has a edittext, in the last few item, EditText first click the interface can also eject up, normal display,
But the second click, the software disk will be the last few of the item to live properly. This affects the user experience very much.
In fact, as long as the solution to think about, I believe that experienced developers can think of, let the soft keyboard disappear when the corresponding item in the edittext disappeared Focus clearfouce (); But there's a key problem,
When you get a return event, if you get an event that's not right, you won't achieve the desired result. This back time must be a custom layout in the back of events.
directly on the code.
Copy Code code as follows:
<cn.test.systemsetting.mylayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/keyboardlayout"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:background= "@drawable/MAIN_BG"
android:orientation= "Vertical" >
<listview
Android:id= "@+id/lv_data"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1"
Android:cachecolorhint= "#00000000"
Android:transcriptmode= "Normal"
>
</ListView>
</cn.test.systemSetting.MyLayout>
Customize the processing that is done in layout:
Copy Code code as follows:
Package cn.test.systemSetting;
Import com.********. R
Import Android.content.Context;
Import Android.util.AttributeSet;
Import android.view.KeyEvent;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.inputmethod.InputMethodManager;
Import Android.widget.EditText;
Import Android.widget.LinearLayout;
/**
*
* Handling keyboard events for device management
* divID Xiao Shuo
*
* **/
public class Mylayout extends LinearLayout {
private context;
Public Mylayout {
Super (context);
TODO auto-generated Constructor stub
This.context=context;
Layoutinflater.from (context). Inflate (R.layout.device_manager, this);//The layout loaded here is the XML above, that is, its name is Device_ Manager.xml
}
Public Mylayout (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
TODO auto-generated Constructor stub
}
Public Mylayout (context context, AttributeSet Attrs) {
Super (context, attrs);
TODO auto-generated Constructor stub
}
@Override
public boolean Dispatchkeyeventpreime (KeyEvent event) {
TODO auto-generated Method Stub
if (context!=null) {
Inputmethodmanager IMM = (inputmethodmanager) context.getsystemservice (Context.input_method_service);
if (imm.isactive () && event.getkeycode () = = Keyevent.keycode_back) {
View view = DeviceManagerActivity.lv_data.getFocusedChild ();
if (view!=null) {
View.clearfocus ();
}
}
}
Return Super.dispatchkeyeventpreime (event);
}
}
The main interface is loaded in such a way that:
Copy Code code as follows:
public class Devicemanageractivity extends activity implements onclicklistener{
public static ListView Lv_data;
static Devmgradapter adapter;
protected void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
//1. Full Screen
Requestwindowfeature (Window.feature_no_title); Untitled
GetWindow (). SetFlags (WindowManager.LayoutParams.FLAG_ Fullscreen,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
This.setcontentview (This) (new mylayout);
init ();
}
}