我在片段中有一个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);
}
当用户单击ActionBar上的按钮时,将调用以下方法。
由于它包含notifyDataSetChanged()
,我希望ListView能够刷新,但这不会发生......
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));
}
感谢您的帮助!