View多次排序ArrayAdapter时出现问题

时间:2010-11-27 10:52:06

标签: android sorting refresh android-arrayadapter

我的代码有问题。我修改了ArrayAdapter的内容,并将其作为参数排序到包含该数组的对象。问题是修改视图(是一个listview)与不同的东西,图标,更改背景等。事实是,通过使排序似乎混合了一些视图的属性。例如,由于移动而传播到另一个的背景和类似的东西:

public class IconLVAdapter extends ArrayAdapter<Datos> {

        private List<Datos> objetos;
        private boolean online;

        public IconLVAdapterBuses(Context context, int textViewResourceId, List<Datos> objetos, boolean online) {
                super(context, textViewResourceId, objetos);
                this.objetos = objetos;
                this.online = online;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                if (v == null) {
                    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    v = vi.inflate(R.layout.rowlist, null);
                }
                Datos o = objetos.get(position);
                if (o != null) {

                        TextView tvNum = (TextView) v.findViewById(R.id.num);

                        if (o.getpOrigen()==null && tvNum!= null)
                            tvNum.setText(o.getnum());
                        else{
                                       ************** omitido **************
                        }

                }
                return v;
        }



        public void refreshArray(){
            this.sort(new Comparator<Datos>() {
                public int compare(Datos object1, Datos object2) {
                    return object1.compareTo(object2);
                };
            });
            this.notifyDataSetChanged();
        }

有什么想法吗?感谢

1 个答案:

答案 0 :(得分:0)

您可以在对适配器进行排序后尝试调用http://developer.android.com/reference/android/widget/AbsListView.html#invalidateViews()吗?