Android:如何在自定义SimpleAdapter中删除项目时刷新列表
在自定义SimpleAdapter中删除映射列表项后,我可以知道如何刷新ListView项吗 我已经用list.remove(position)成功地实现了删除列表项,但是当我尝试调用list.notifyAll()函数时,它给了我类似“java.lang.IllegalMonitorStateException:对象在notifyAll()之前未被线程锁定”的错误消息 我希望你能帮助我。下面是定制SimpleAdapter的代码Android:如何在自定义SimpleAdapter中删除项目时刷新列表,android,listview,notify,delete-row,simpleadapter,Android,Listview,Notify,Delete Row,Simpleadapter,在自定义SimpleAdapter中删除映射列表项后,我可以知道如何刷新ListView项吗 我已经用list.remove(position)成功地实现了删除列表项,但是当我尝试调用list.notifyAll()函数时,它给了我类似“java.lang.IllegalMonitorStateException:对象在notifyAll()之前未被线程锁定”的错误消息 我希望你能帮助我。下面是定制SimpleAdapter的代码 public class DeleteAdapter exten
public class DeleteAdapter extends SimpleAdapter {
Context context;
List<? extends Map<String, ?>> list;
int resource;
String[] from;
int[] to;
public FDeleteAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
this.context = context;
this.list = data;
this.resource = resource;
this.from = from;
this.to = to;
// TODO Auto-generated constructor stub
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final View row = super.getView(position, convertView, parent);
final Button delete = (Button) row.findViewById(R.id.deletebut);
final TextView title = (TextView) row.findViewById(R.id.label);
delete.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
deleteDialog xdialog = new deleteDialog(context, "Delete? ", position) {
@Override
public boolean onOkClicked() {
list.remove(position);
list.notifyAll();
return true;
}
};
xdialog.show();
}
});
return row;
}
};
公共类DeleteAdapter扩展SimpleAdapter{
语境;
列表>列表;
智力资源;
字符串[]来自;
int[]至;
公共FDeleteAdapter(上下文,列表>数据,
int资源,字符串[]从,int[]到){
超级(上下文、数据、资源、从、到);
this.context=上下文;
this.list=数据;
这个资源=资源;
this.from=from;
这个;
//TODO自动生成的构造函数存根
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
最终视图行=super.getView(位置、转换视图、父级);
final Button delete=(Button)row.findviewbyd(R.id.deletebut);
最终文本视图标题=(文本视图)行.findViewById(R.id.label);
delete.setOnClickListener(新的OnClickListener(){
公共void onClick(视图){
deleteDialog xdialog=新建deleteDialog(上下文“删除?”,位置){
@凌驾
公共布尔值onOkClicked(){
列表。删除(位置);
list.notifyAll();
返回true;
}
};
xdialog.show();
}
});
返回行;
}
};
提前感谢您的帮助 您应该调用适配器的函数,而不是列表中的notifyAll() 使用
this.notifyDataSetChange();
notifyAll()告诉其他适配器或线程它已完成更新或正在执行其工作。但它显示“无法从类型对非静态方法notifyDataSetChanged()进行静态引用”…您可以教我如何解决它吗?但它显示“无法从类型对非静态方法DataNotifyDataSetChanged()进行静态引用”…你能教我怎么解决吗?使用DeleteAdapter。android.widget.ListAdapter的.notifyDataSetChanged()
notifyDataSetChanged()
不存在。