I am trying to rename an image file in my app . But the code is not working .
Basically, I want user to click on Rename button , pop up an alert dialog with an editText, user enters the new name of the image , and selects Rename option. This should rename the file but it does nothing. Also I am not getting any errors or exceptions. But a warning, Result of 'File.renameTo()' is ignored.
How do I fix it ?
buttonRename.setOnClickListener(
new View.OnClickListener(){
public void onClick(View view){
AlertDialog.Builder builder2 = new AlertDialog.Builder(PhotosActivity.this);
builder2.setMessage("Rename File");
final EditText input = new EditText(PhotosActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
builder2.setView(input);
builder2.setPositiveButton(
"Rename",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
File oldName =new File(al_images.get(int_position).getAl_imagepath().get(position));
String string = input.getText().toString();
boolean success = oldName.renameTo(new File(string));
if(!success){
Log.v(TAG,"not renamed");
}
}
});
builder2.setNegativeButton(
"Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert12 = builder2.create();
alert12.show();
}
}
);