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
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanghfaca
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20