显示在ListiView最后一个项目,当你点击编辑文本 [英] Show last item in ListiView when you click on edit text

查看:395
本文介绍了显示在ListiView最后一个项目,当你点击编辑文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我这样做是为了得到一个列表视图的最后一个项目的重点点击编辑文本后:

currently I'm doing this to get the focus of the last item in a listview after clicking on an edit text:

    bodyText.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {               
            getListView().setSelection(getListView().getCount());
        }
    });

    bodyText.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            getListView().setSelection(getListView().getCount());
        }
    });

它的伟大工程,并抓住最后一个项目,问题是软键盘出现,并涵盖过去的3个项目的列表视图。有没有一种方法,以显示最后一个项目之后的软键盘出现并调整屏幕?谢谢!

It works great and grabs the last item, problem is the soft keypad appears and covers the last 3 items in the listview. Is there a way to show the last item AFTER the soft keypad appears and resizes the screen? Thanks!

推荐答案

我在我自己的自定义的ListView是这样的:

I made my own Custom ListView like this:

public class CustomListView extends ListView {

public CustomListView (Context context) {
    super(context);
}

public CustomListView (Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomListView (Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onSizeChanged(int xNew, int yNew, int xOld, int yOld) {
    super.onSizeChanged(xNew, yNew, xOld, yOld);

    setSelection(getCount());

}
}

您必须包括所有3构造函数或将引发异常。

You must include all 3 constructors or an exception will be thrown.

然后在你平时把XML

Then in the XML where you usually put

的ListView

android:id="@+id/android:list"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"

修改的ListView com.blah.blah.CustomListView

对不起,我凌乱的布局,由于某种原因,我无法格式化才能正常工作。

Sorry for the messy layout, for some reason I can't get the formatter to properly work.

运行应用程序。现在,当你点击的EditText,它显示了软键盘显示在最后一个项目!请注意,有些情况下,自动完成功能,当你键入文字的EditText像出现一定的局限性,它会显示的最后一个项目,以及由于在ListView大小的变化。

Run your application. Now when you click on the EditText, it shows the last item AFTER the soft keyboard shows! Note that there are some limitations like when the auto-complete function appears when you type text in the EditText, it will show the last item as well due to a change in size of the ListView.

享受!

这篇关于显示在ListiView最后一个项目,当你点击编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆