从另一个类的ListView更新项目 [英] Update ListView items from another class
问题描述
我有一个问题,当我尝试更新我的列表视图
值。我有一个由编辑文本组成的自定义适配器。当我在编辑文本中单击我展示一个对话框(这是另一个类),并传给他喜欢的位置,arralist等。
I have an issue when I try to update my listview
values. I have a Custom Adapter that is composed by edit text. When i click on an edit text I show a dialog (that is in another class) and pass to him same values like position, arralist and other.
在对话框类我有这个方法
In the dialog class I've this method
public void updateValue(String newValue) {
MyObject object = arrayList.get(position);
object.valueFile = newValue;
arrayList.set(position, object);
MyAdapter adapter = new MyAdapter(context, 0, arrayList);
adapter.notifyDataSetChanged();
}
这个方法有效,因为新的值是否正确插入到数组列表,但编辑文本的文本不更新,但它只更新时我滚动,然后我回到那个editt文本。为什么?我该如何解决?问题出在哪里?
This method works because the new values is correctly insert into the array list but the text of the edit text is not updated BUT it only updates when I scroll, and then I go back to that editt text. Why? How can I fix? Where is the problem?
推荐答案
您不能将新()适配器的第二次。该适配器只能新()一次。
如果您想更新列表视图,您需要在您的ArrayList来更新数据。
You cannot New() your adapter at the second time. The adapter can only New() one time.
If you want to update listview, you need to update data in your arrayList
ArrayList<yourType> arrayList = new ArrayList<yourType>();
//Init data for your arrayList
//...
//Init your adapter
MyAdapter adapter = new MyAdapter(context, 0, arrayList);
//update item of listview
public void updateValue(String newValue) {
arrayList.get(position).valueFile = newValue;
adapter.notifyDataSetChanged();
}
这篇关于从另一个类的ListView更新项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!