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 失去对点击的关注
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
