的EditText失去焦点的点击 [英] EditText Loses Focus on Click

查看:227
本文介绍了的EditText失去焦点的点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个活动列出一串从数据库项目,并显示出与量的附加列。我实现了一个ArrayAdapter显示我的自定义布局。
下面是适配器的最重要部分的code:

I'm writing an activity to list a bunch of items from the database and show an additional column with a quantity. I implemented an ArrayAdapter to show my custom layout. Here is the code of the most important parts of the Adapter:

static class ViewHolder {
    protected TextView text;
    protected EditText editText;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = null;
    if (convertView == null) {
        LayoutInflater inflator = context.getLayoutInflater();
        view = inflator.inflate(R.layout.rowquantitylayout, null);
        final ViewHolder viewHolder = new ViewHolder();
        viewHolder.text = (TextView) view.findViewById(R.id.label);
        viewHolder.editText = (EditText) view.findViewById(R.id.editText);
        viewHolder.editText.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable s) {
                Log.i(TAG, "Editable:" + s.toString());
            }

            public void beforeTextChanged(CharSequence s, int start,
                    int count, int after) {
            }

            public void onTextChanged(CharSequence s, int start,
                    int before, int count) {
            }
        });
        view.setTag(viewHolder);
        viewHolder.editText.setTag(list.get(position));
    } else {
        view = convertView;
        ((ViewHolder) view.getTag()).editText.setTag(list.get(position));
    }
    ViewHolder holder = (ViewHolder) view.getTag();
    holder.text.setText(list.get(position).getDescription());
    holder.editText.setText("" + list.get(position).getQuantity());
    return view;

}

现在,当我试图把重点放在的EditText,失去焦点就在我点击它。它显示了接口的键盘,它甚至获取到Log.i,但犯规让我改变的值,因为它不集中。

Now, when I try to focus the "EditText" it loses focus just after I clicked it. It shows the keboard and it even gets to the Log.i, but doesnt let me change the value since it is not focused.

感谢您的帮助。

推荐答案

我有同样的问题,我搜索了一个答案。
这里是一个答案,一个类似的问题: http://stackoverflow.com/a/9338694/1448661

I had the same problem and I searched for an answer. Here is an answer to a similar question : http://stackoverflow.com/a/9338694/1448661

您必须把线在你的活动清单:

You have to put a line in your activity in the manifest :

    android:windowSoftInputMode="adjustPan"

和您的ListView必须要有这行太:

And your listview must have this line too :

    android:descendantFocusability="beforeDescendants"

现在,你可能会面临被滚动的时候失去了你的文字的另一个问题。如果发生这种情况看看这个教程:
<一href=\"http://vikaskanani.word$p$pss.com/2011/07/27/android-focusable-edittext-inside-listview/\">http://vikaskanani.word$p$pss.com/2011/07/27/android-focusable-edittext-inside-listview/

希望这会有所帮助。
Goui

Hope this will help. Goui

这篇关于的EditText失去焦点的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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