gpt4 book ai didi

android - 我无法写入 EditText,当我尝试写入内容时它消失了,这是因为当我修改数据时调用了 getView()

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:44 25 4
gpt4 key购买 nike

编辑:

I found the reason which is that the getView() is called when i try to edit something, so the data from the DataAdapter is loaded & my edited changes disappears.

编辑:

i observed one thing, if there are few rows in the listview then its OK, but if there are many rows which the listview can not show in the visible screen (Scroll bar appears to scroll to other records), then the issue arises!!

我正在开展一个项目,我们已经实现了一个 INLINE EDITING using ListView ,即可以在 ListView 中编辑数据。

我为该 ListView 的每个项目/行定义了一个 xml。我正在使用 Custom DataAdapter 将数据与 ListView 绑定(bind)。

当我第一次加载 ListView 加载的 Activity 时,我可以编辑数据并且它工作正常。当编辑某些内容时,更改会保存到 SQLite 数据库中,我有一个用于此目的的按钮。

现在的问题是,在第一次保存数据并再次加载 ListView 后,我无法再编辑数据。当我尝试编辑数据时,键盘出现然后自动消失,输入的数据也消失了。请查看屏幕截图。

有人可以帮我解决这个问题吗?

我的自定义适配器类:

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

}

}

enter image description here

最佳答案

尝试修改你的代码,看看是否Adapter.getView(..)方法在不应该被调用的时候被调用。这可能是由于冗余调用 notifyDataSetChanged() 而发生的.

只需向这些方法添加日志记录,看看它们是否在正确的时间和地点被调用。

关于android - 我无法写入 EditText,当我尝试写入内容时它消失了,这是因为当我修改数据时调用了 getView(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com