EditText Loses Focus on Click(EditText 失去对点击的关注)
问题描述
我正在编写一个活动来列出数据库中的一堆项目并显示一个带有数量的附加列.我实现了一个 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 失去对点击的关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EditText 失去对点击的关注


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01