title: How to rename audio file which is in sd card programmatically?
body: <p>Here is my code to display all music file names in a list view ,here i am taking all files in an array list then displaying in a listview,by using contextmenu performing "rename" on listitems but these changes are not effecting actual file which is in sd card ,suggest me how to do this ,i tried file operations like this.</p>
  
  <pre><code>path = "/sdcard/";
      if (getIntent().hasExtra("path")) {
          path = getIntent().getStringExtra("path");
      }
      setTitle(path);
      // Read all files sorted into the values-array
      values = new ArrayList();
      File dir = new File(path);
      if (!dir.canRead()) {
          setTitle(getTitle() + " (inaccessible)");
      }
      final String[] list = dir.list();
      if (list != null) {
          for (String file : list) {
              if (file.contains(".3gp")) {
                  values.add(file);
              }
          }
      }
      Collections.sort(values);
      // Put the data into the list
      adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2,
              android.R.id.text1, values);
      setListAdapter(adapter);
      registerForContextMenu(myList);
  }
  
  final int CONTEXT_MENU_DELETE = 1;
  final int CONTEXT_MENU_RENAME = 2;
  
  @Override
  public void onCreateContextMenu(ContextMenu menu, View v,
          ContextMenu.ContextMenuInfo menuInfo) {
      menu.add(Menu.NONE, CONTEXT_MENU_DELETE, Menu.NONE, "silmek");
      menu.add(Menu.NONE, CONTEXT_MENU_RENAME, Menu.NONE, "adını değiştirmek");
  }
  
  @Override
  public boolean onContextItemSelected(MenuItem item) {
  
      AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item
              .getMenuInfo();
      Long id = myList.getAdapter().getItemId(info.position);
      final int number_of_item_in_listview = Integer.valueOf(id.intValue());
      final int context_menu_number = item.getItemId();
  
      switch (item.getItemId()) {
  </code></pre>
  
  <p>This is how i am renaming file prgrammatically using contextmenu for listview</p>
  
  <pre><code>case CONTEXT_MENU_RENAME:
  
          AlertDialog.Builder alert = new AlertDialog.Builder(this);
          alert.setTitle("öğeyi yeniden adlandırmak");
          alert.setMessage("Seçili öğe için yeni bir isim girin");
  
          final EditText input = new EditText(this);
          alert.setView(input);
  
          alert.setPositiveButton("tamam",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog,
                              int whichButton) {
                          String value = input.getText().toString();
                          values.set(number_of_item_in_listview, value
                                  + ".3gp");
                          adapter.notifyDataSetChanged();
                          /*
                           * File sdcard =
                           * Environment.getExternalStorageDirectory(); File
                           * from = new File(sdcard,"from.txt"); File to = new
                           * File(sdcard,"to.txt"); from.renameTo(to);
                           */
                          File f = new File(path + filename);
                          if (f != null &amp;&amp; f.exists()) {
                              File from = new File(f, f.getName());
                              File to = new File(f, value);
                              from.renameTo(to);
                          }
  
                      }
                  });
  
          alert.setNegativeButton("iptal",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog,
                              int whichButton) {
                      }
                  });
          alert.show();
          return (true);
      }
      return (super.onOptionsItemSelected(item));
  </code></pre>