Android 为什么片段中的ListView不';没有更新吗?

Android 为什么片段中的ListView不';没有更新吗?,android,listview,android-fragments,android-adapter,Android,Listview,Android Fragments,Android Adapter,我在片段中有一个ListView: public class EditorFragment extends SherlockFragment { private EditText editor = null; private ListView lv = null; private EditText et = null; private File root = null; private String[] nomi={"test1","test2"}; private Ar

我在片段中有一个ListView:

public class EditorFragment extends SherlockFragment {
  private EditText editor = null;
  private ListView lv = null;
  private EditText et = null;
  private File root = null;
  private String[] nomi={"test1","test2"};
  private ArrayAdapter<String> aa;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup parent,
                                                 Bundle savedInstanceState) {
    setHasOptionsMenu(true);

    View result = inflater.inflate(R.layout.editor, parent, false);

    editor = (EditText) result.findViewById(R.id.editor);
    lv = (ListView) result.findViewById(R.id.list);
    root = getActivity().getExternalFilesDir(null);
    aa = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, nomi );
    lv.setAdapter(aa);
    return (result);
}

谢谢你的帮助

您正在更改
nomi
引用,希望它更改
aa
中的引用,但这是不对的。如果要更改
aa
的数据,必须更改
nomi
并再次将其设置为
aa
。不要在
getTarget()
上调用
aa.notifyDataSetChanged()
,而是尝试创建一个新的
ArrayAdapter
并再次将其设置为
ListView
。在调用
aa.notifyDataSetChanged
之前,需要使用新的数据集更新适配器。在您的代码中看不到这种情况。@LisaAnne,您对对象引用的理解有误。把对象想象成C指针(若你们以前见过C的话),你们可能很容易理解你们的错误,因为它起作用了!!!如果你发布一个答案,我将欣然接受:-)
private File getTarget() {
  int i = 0;
  if(et!=null)
        FILENAME=et.getText().toString();
  if(root.list().length!=0) {
        nomi= new String[(int) root.length()];
        nomi=root.list();
  };
  aa.notifyDataSetChanged();
  return (new File(root,FILENAME));
}