我有一个文件列表,当用户保存文件时,我想刷新列表,以便显示新文件。这就是我尝试过的。
private IconifiedTextListAdapter itla = new IconifiedTextListAdapter(this);
...
private void saveAs(){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Save as");
alert.setMessage("(Will be saved in the current working directory)");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
String tmpText = et.getText().toString();
try {
File tempfile = new File(currentDirectory, value);
FileWriter writer = new FileWriter(tempfile);
writer.write(tmpText);
writer.flush();
writer.close();
changed=false;
itla.notifyDataSetChanged();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
答案 0 :(得分:0)
private void saveAs(final Intent intent) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Save as");
alert.setMessage("(Will be saved in the current working directory)");
// Set an EditText view to get user input
final EditText input = new EditText(this);
input.setText(ending);
alert.setView(input);
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
String tmpText = et.getText().toString();
if (!value.contains(".")) {
value = value + ending;
}
try {
File tempfile = new File(currentDirectory, value);
FileWriter writer = new FileWriter(tempfile);
writer.write(tmpText);
writer.flush();
writer.close();
changed = false;
exists = true;
String newFile = new File(currentDirectory + "//" + value)
.getPath();
currentFile = new File(newFile);
fill(currentDirectory.listFiles());
Log.i("saveAs", currentFile.getPath());
return;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});