在滚动列表中失去了改变的EditText项目时滚动到屏幕 [英] EditText items in a scrolling list lose their changes when scrolled off the screen

查看:183
本文介绍了在滚动列表中失去了改变的EditText项目时滚动到屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SimpleCursorAdapter和$ P $从SQLite数据库ppopulated与价值创造的EditText项长期滚动列表。

我有这样的人:

 光标= db.rawQuery(选择_id,标准,localweight,globalweight FROM+ dbTableName +ORDER BY准则,NULL);

startManagingCursor(光标);

mAdapter =新SimpleCursorAdapter(这一点,R.layout.weight_edit_items,光标,新的String [] {标准,localweight,globalweight},新的INT [] {R.id.criterion_edit,R.id.localweight_edit, R.id.globalweight_edit});

this.setListAdapter(mAdapter);
 

滚动列表是几模拟器屏幕长。该项目显示OK - 通过他们的滚动显示,每个人都有从数据库中正确的值

我可以编辑更改任何EditTexts,新文本被接受并显示在对话框。

不过......如果我再滚动列表远远不够坐编辑项目关闭屏幕,当我向后滚动来再看看它的价值又回到了那是什么之前,我做了修改,即得。我的编辑已经丢失。

在试图理清了这一点,我已经做了的getText来看看什么是在EditText上我做了后,我的编辑(和滚动前)和gettext的返回文字,即使是的EditText显示我的文本。看来,EditText上才接受了我的编辑表面上,他们并没有被绑定到的EditText,这意味着当滚动出屏幕,他们会被丢弃。

谁能告诉我这是怎么回事,什么我需要做强制的EditText保留它修改?

感谢

伊恩

解决方案
  

不过......如果我再滚动列表远   足以把编辑的项目关闭   屏幕上,当我向后滚动来看看   再次它的价值已恢复   这是什么之前,我所做的更改,   IE浏览器。我的编辑已经丢失。

当然。

表行得到回收。你的光标可有1000条记录,但不会是1000 的EditText 如果您滚动列表创建的小部件。相反,将有10个左右,取决于有多少行是同时可见的。行得到回收,并且绑定操作将取代旧的的EditText 值从光标新价值的任何行只是滚动到屏幕上,更换什么是有前($ P从数据库或用户编辑值$ pvious值)。

和,因为普通的光标是不可变的,你没有办法坚持所有编辑的方式,将透明地放回列表中。

我怀疑它可以创建一个的ListView 与行是 EditTexts ,可能是通过创建一个自定义的适配器类,并处理所有​​的行回收自己。然而,将是工作的相当数量,且内置类只会给你一点支持这种模式。

I have a long scrolling list of EditText items created by a SimpleCursorAdapter and prepopulated with values from an SQLite database.

I make this by:

cursor = db.rawQuery("SELECT _id, criterion, localweight, globalweight FROM " + dbTableName + " ORDER BY criterion", null);

startManagingCursor(cursor);

mAdapter = new SimpleCursorAdapter(this, R.layout.weight_edit_items, cursor, new String[]{"criterion","localweight","globalweight"}, new int[]{R.id.criterion_edit, R.id.localweight_edit, R.id.globalweight_edit});    

this.setListAdapter(mAdapter);

The scrolling list is several emulator screens long. The items display OK - scrolling through them shows that each has the correct value from the database.

I can make an edit change to any of the EditTexts and the new text is accepted and displayed in the box.

But...if I then scroll the list far enough to take the edited item off the screen, when I scroll back to look at it again its value has returned to what it was before I made the changes, ie. my edits have been lost.

In trying to sort this out, I've done a getText to look at what's in the EditText after I've done my edits (and before a scroll) and getText returns the original text, even though the EditText is displaying my new text. It seems that the EditText has only accepted my edits superficially and they haven't been bound to the EditText, meaning they get dropped when scrolled off the screen.

Can anyone please tell me what's going on here and what I need to do to force the EditText to retain its edits?

Thanks

Ian

解决方案

But...if I then scroll the list far enough to take the edited item off the screen, when I scroll back to look at it again its value has returned to what it was before I made the changes, ie. my edits have been lost.

Of course.

List rows get recycled. Your Cursor may have 1,000 records, but there are not going to be 1,000 EditText widgets created if you scroll through the list. Rather, there will be 10 or so, depending on how many rows are simultaneously visible. Rows get recycled, and the binding operation will replace the old EditText value with a new value from the Cursor for whatever row just scrolled onto the screen, replacing whatever was there before (previous value from the database or a user-edited value).

And, since a regular Cursor is immutable, you have no way of persisting any edits in a way that will transparently be put back into the list.

I suspect it is possible to create a ListView with rows that are EditTexts, probably by creating a custom Adapter class and handling all the row recycling yourself. However, it is going to be a fair amount of work, and the built-in classes will only give you a bit of support for this pattern.

这篇关于在滚动列表中失去了改变的EditText项目时滚动到屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆