GridView to rename file name
<p>I use below code to show photo in GridView:</p>

<pre><code>String[] projection = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, MediaStore.Images.ImageColumns.DATA};  
Cursor cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, MediaStore.Images.Media._ID); 
int count = cursor.getCount();
int image_column_index = cursor.getColumnIndex(MediaStore.Images.Media._ID);
int image_path_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
fd.clearPhonePhoto();
int i;
for(i = 0; i &lt; count; i++) {
cursor.moveToPosition(i);
int id = cursor.getInt(image_column_index);
String p = cursor.getString(image_path_index);
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getApplicationContext().getContentResolver(), id, MediaStore.Images.Thumbnails.MICRO_KIND, null);
FilePath.add(p);  
FileThumb.add(b); 
}

b4 = (Button)findViewById(R.id.btn_4);
b4.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int i;
for(i = 0; i &lt; Check.length; i++) {
if(Check[i]) {
AlertDialog.Builder renameDialog = new AlertDialog.Builder(PhonePhotoListActivity.this);
renameDialog.setTitle("Rename");
final EditText name = new EditText(AActivity.this);
name.setText(FilePath.get(i).substring(FilePath.get(i).lastIndexOf("/") + 1));   //set old file name
renameDialog.setView(name);
final String oripath = FilePath.get(i);
renameDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
rename(oripath, name.getText().toString());
Intent it = new Intent(AActivity.this, AActivity.class);
it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);


startActivity(it); 
}
});
renameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {}
});
renameDialog.show();
}
}
}
});
gv = (GridView)findViewById(R.id.phone_photo);
AAdapter = new AAdapter(this, FilePath, FileThumb);
gv.setAdapter(AAdapter);
</code></pre>

<p>Above in onCreate().
rename() method as below:</p>

<pre><code>public void rename(String ori, String edit) {
File rename = new File(ori);
String newpath = ori.substring(0, ori.lastIndexOf("/") + 1) + edit;
rename.renameTo(new File(newpath));
}
</code></pre>

<p>In first time, the dialog show the correct file name and rename the file name success.
But second time, the dialog show the old file name which is not renamed, and rename failed.
How to modify to avoid it?</p>

<p>I try to restart the app, it still show the old file name.</p>
