【发布时间】:2012-02-23 07:11:18
【问题描述】:
编辑:
我找到了当我尝试调用 getView() 的原因 编辑一些东西,所以来自 DataAdapter 的数据被加载 & 我编辑 更改消失。
编辑:
我观察到一件事,如果列表视图中的行数很少,那么它 好的,但是如果列表视图中有很多行无法显示在 可见屏幕(出现滚动条以滚动到其他记录),然后 问题出现了!!
我正在做一个我们已经实现INLINE EDITING using ListView 的项目,即可以在列表视图中编辑数据。
我为该 ListView 的每个项目/行定义了一个 xml。我正在使用自定义 DataAdapter 将数据与 ListView 绑定。
当我第一次加载 ListView 加载的活动时,我可以编辑数据并且它工作正常。编辑某些内容时,更改会保存到 SQLite 数据库中,为此我有一个按钮。
现在的问题是,在第一次保存数据并再次加载列表视图后,我无法再编辑数据了。当我尝试编辑数据时,键盘出现然后自动消失,输入的数据也消失了。请查看屏幕截图。
谁能帮我解决这个问题?
我的自定义适配器类:
public class QuestionAdapter extends ArrayAdapter<QuestionEntity> {
private ArrayList<QuestionEntity> items;
private Context CurrentContext;
private QuestionEntity CurrentItem;
private Cursor OptionsCursor;
public QuestionAdapter(Context context, ArrayList<QuestionEntity> items, Cursor curOptions)
{
super(context, R.layout.grid_item, items);
this.CurrentContext = context;
this.items = items;
this.OptionsCursor = curOptions;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
//verify that the items list is still valid since
//the list may have been cleared during an update
if ((items == null) || ((position + 1) > items.size()))
return convertView; //Can't extract item
CurrentItem = items.get(position);
if(convertView == null)
{
LayoutInflater inflater = LayoutInflater.from(CurrentContext);
convertView = inflater.inflate(R.layout.grid_item, null);
}
if (convertView != null)
{
TextView txtQuestion = (TextView) convertView.findViewById(R.id.txtQuestion);
txtQuestion.setText(CurrentItem.getTitle());
Spinner cmbOptions = (Spinner)convertView.findViewById(R.id.cmbOptions);
/*
* Load the options from OptionsCursor
*/
LoadOptions(cmbOptions);
/*
* Attach onItemClick event with cmbOptions
* When the user change the option we will populate the comments based on the option
*/
cmbOptions.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id)
{
try
{
//If MyCondition is true show msg to user.
}
catch(Exception ex)
{
ex.toString();
}
}
});
}
return convertView;
}
private void LoadOptions(Spinner iacOptions)
{
//Load data in the spinner using the OptionsCursor
}
}
【问题讨论】:
标签: android listview android-edittext android-softkeyboard inline-editing