【问题标题】:android listview order changed when called notifyDataSetChanged调用 notifyDataSetChanged 时,android listview 顺序更改
【发布时间】:2011-06-30 07:03:54
【问题描述】:

全部。 当我使用 notifyDataSetChanged() 时,listview 的显示顺序会发生变化。

喜欢这个

  • 3
  • 2
  • 1

    当前活动的创建时间。但是当我更改数据时。会是

  • 1
  • 2
  • 3

我不想改变订单,我不明白为什么会这样。

这是我的适配器类中的一段代码

    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();
        }



}

我在这样的对话框中更改数据

       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();
}})

【问题讨论】:

  • 目前看起来还不错。让我们看看您对 Adapter.getView() 的实现。
  • 发布一段从适配器创建适配器和 getView() 方法的 sn-p 代码。您还可以添加一个 sn-p 如何获取“关键”变量。

标签: android listview baseadapter


【解决方案1】:

如果不查看适配器的完整源代码,很难判断发生了什么,但这听起来像是您的 getView() 实现中的一个问题。每次调用 getView() 时,您必须重新绑定所有数据。

【讨论】:

    【解决方案2】:

    在我看来,在 setEditText 中您实际上是在更改列表内容,因此这可能是开始寻找问题的好地方。

    【讨论】:

      【解决方案3】:

      我认为不要使用private String[] mData;,你应该使用以下,

      private ArrayList mData = new ArrayList();
      mData.add(item);
      

      在我的情况下,它可以工作并且不会改变数据,我希望你能解决你的问题。

      【讨论】:

      • 感谢您的回复,我昨天试了一下,数据类型有问题。我稍后会尝试。当我成功时,我会在这里发布。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 2011-02-24
      • 1970-01-01
      相关资源
      最近更新 更多