所有。 当我使用notifyDataSetChanged(),列表视图显示顺序将改变。
像这样
3 21
在当前activy已创建。但是当我改变数据。这将是
1 2 3我不希望的顺序改变,我不明白为什么它的发生。
这是一张code从我的适配器类
公共静态类ItemAdapter延伸BaseAdapter { 私有String [] MDATA; 私人LayoutInflater mInflater;//我叫这种方法来改变数据 公共无效setEditText(INT位置,最后弦乐项){ MDATA [位置] =项目; notifyDataSetChanged(); }}
我在一些像这样的对话框更改数据
=建设者新AlertDialog.Builder(CT); builder.setTitle(R.string.pickStatus) .setView(edBuffer) .setPositiveButton(R.string.save,新DialogInterface.OnClickListener(){ @覆盖 公共无效的onClick( DialogInterface对话框,INT ID){ // TODO自动生成方法存根 canPop = TRUE; 。最后弦乐TMP = edBuffer.getText()的toString(); KbonezLog.e(的String.format(套入钥匙%D键));//使用MDATA键设定值setEditText(键,TMP);dialog.dismiss();}})
解决方案
我已经遇到了类似的问题here
我通过始终创造getView()implemantation新ViewHolder解决它。
所以我觉得罗曼盖伊提供正确的途径解决的问题,例如种。
希望工程。
all. when I use notifyDataSetChanged(), the listview display order will be change .
like this
3 21
when current activy was created. but when I change the data. it will be
1 2 3I don't want the order changed and i dont understand why its happening.
This is a piece of code from my adapter class
public static class ItemAdapter extends BaseAdapter {
private String[] mData;
private LayoutInflater mInflater;
// I called this method to change data
public void setEditText(int position, final String item) {
mData[position] = item;
notifyDataSetChanged();
}
}
I change data at some dialog like this
builder = new AlertDialog.Builder(ct);
builder.setTitle(R.string.pickStatus)
.setView(edBuffer)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog, int id) {
// TODO Auto-generated method stub
canPop = true;
final String tmp = edBuffer.getText().toString();
KbonezLog.e(String.format( "set into key %d", key));
//use mData key to set value
setEditText(key, tmp);
dialog.dismiss();
}})
解决方案
I've encountered a similiar problem here
I solved it by always creating a new ViewHolder in getView() implemantation.
So I think Romain Guy provide the correct way to solving such kinds of problems.
Hope it works.