Android Basics Android's ListView and EditText conflict resolution approach _android

Source: Internet
Author: User
Tags stub

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.