EditText 失去对点击的关注

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

问题描述

限时送ChatGPT账号..

我正在编写一个活动来列​​出数据库中的一堆项目并显示一个带有数量的附加列.我实现了一个 ArrayAdapter 来显示我的自定义布局.下面是Adapter最重要部分的代码:

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"时,它会在我单击它后失去焦点.它显示了 keboard,它甚至到达了 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.

感谢您的帮助

推荐答案

我遇到了同样的问题,我正在寻找答案.这是对类似问题的回答:https://stackoverflow.com/a/9338694/1448661

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

您必须在清单中的活动中添加一行:

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

    android:windowSoftInputMode="adjustPan"

你的列表视图也必须有这一行:

And your listview must have this line too :

    android:descendantFocusability="beforeDescendants"

现在您可能会面临另一个问题,即滚动时文本丢失.如果发生这种情况,请查看本教程:http://vikaskanani.wordpress.com/2011/07/27/android-focusable-edittext-inside-listview/

And now you will probably face another problem which is the lost of your text when scrolling. If this happens take a look at this tutorial : http://vikaskanani.wordpress.com/2011/07/27/android-focusable-edittext-inside-listview/

希望这会有所帮助.勾芡

Hope this will help. Goui

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

上一篇:Android:用户完成编辑后评估 EditText 下一篇:如何从 Edittext 中检索多行文本?

相关文章

最新文章