Android:ListView 中有很多编辑文本
这是我的 getView 方法:
public View getView(final int position, View convertView, final ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.propviewlistrow, null);
holder.title = (TextView) convertView.findViewById(R.id.propviewlistrow_t1);
holder.content = (EditText) convertView.findViewById(R.id.propviewlistrow_e1);
convertView.setTag(holder);
}
else{
holder = (ViewHolder)convertView.getTag();
}
holder.title.setText(names.get(position));
holder.content.setText(values.get(position));
holder.content.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
values.set(position, s.toString());
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
return convertView;
}
}
但这不起作用。 edittexts 不显示正确的文本,显示的文本在滚动时切换。 下一个问题是,我在清单中设置了 android:windowSoftInputMode="adjustPan" 。 如果您单击最后一个编辑文本,列表视图将无法向上滚动到足以让您看到正在键入的内容。
this is my getView method:
public View getView(final int position, View convertView, final ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.propviewlistrow, null);
holder.title = (TextView) convertView.findViewById(R.id.propviewlistrow_t1);
holder.content = (EditText) convertView.findViewById(R.id.propviewlistrow_e1);
convertView.setTag(holder);
}
else{
holder = (ViewHolder)convertView.getTag();
}
holder.title.setText(names.get(position));
holder.content.setText(values.get(position));
holder.content.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
values.set(position, s.toString());
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
});
return convertView;
}
}
But this does not work.
The edittexts do not display the proper text, the displayed text switches while scrolling.
The next issue is, I have set android:windowSoftInputMode="adjustPan" in the manifest.
If you click the into the last edittext, the listview won't scroll up enough so that you can see what you are typing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很抱歉没有直接回答您的问题,但如果我是您,我会重新设计该列表。
用户使用列表中的编辑字段将成为主要的 PITA。我会做什么 - 要么使用长按操作并引入对话框或对话框活动进行编辑,要么使用快速操作模式
http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html
Sorry for not answering your question directly, but if i were you i'd redesign that list.
It's gonna be major PITA for the user to use edit fields in the list. What i'd do - either use long-press action and bring dialog or dialog activity to edit, or use quick actions pattern
http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html