Why are my files being multiplied ???? renameTo();
<p>I have an issue with renaming a file it seems every time I try to they end up being multiplied and are created 2 times the amount I.e. if I have one song that I want to rename in the list view and hold the on long click event it doubles the amount say 2 to 4 songs and 4 to 12 and so on in my list view . I'm using an OnItemLongClickListener to handle the files being created for each item click on the list view to be renamed . I have no idea why it isn't working  ... I have even tried setting the position to </p>

<pre><code>    String pos = lv.getItemAtPosition(position); 
</code></pre>

<p>And many other ways ...
But no use it ends up being a random number that is being multiplied ... My question is why ; how can fix .</p>

<pre><code>    downloadsList.setOnItemLongClickListener(
        new OnItemLongClickListener(){
            @Override
            public boolean onItemLongClick(AdapterView&lt;?&gt; parent , View view , int position , long itemId ){
                EditText bar = (EditText)findViewById(R.id.search);
                String to = bar.getText().toString();
(ListView) findViewById(R.id.downloads);
                File[] pos = files.listFiles();
                File filein = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() , files.getName());
                File fileTo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + to);
                if(!filein.exists()){
                    filein.renameTo(fileTo);
                } else {
                    try {
                        throw new IOException("File exists");
                    }catch (IOException e){
                           e.printStackTrace();
                    }
                }

                finish();
                overridePendingTransition(0, 0);
                startActivity(getIntent());
                overridePendingTransition(0, 0);
                return true;
            }
        });
</code></pre>

<p>Here is the list view method to populate it </p>

<pre><code>    private void ShowLists(){
    files = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_DOWNLOADS).toString());

    downloads = files.listFiles(new FileFilter(){
        @Override
        public boolean accept(File file){
            String ext = file.getName();
            if(ext.endsWith(".mp3")){
                return true;
            }
            return false;
        }
    });
    mp3s = new String[downloads.length];
        for(int i = 0 ; i &lt; mp3s.length; i++){
            mp3s[i] = downloads[i].getName();       
        }
    adapter = new ArrayAdapter&lt;String&gt;(this,R.layout.downloads, R.id.textviewone , mp3s);
    ListView downloadsList = (ListView) findViewById(R.id.downloads);
    downloadsList.setAdapter(adapter);
}
</code></pre>

<p>This is before <a href="http://imgur.com/rBmSAXK" rel="nofollow">http://imgur.com/rBmSAXK</a></p>

<p>This is after I click the long click to rename a file and the on going complication <a href="http://imgur.com/I9szC6m" rel="nofollow">http://imgur.com/I9szC6m</a></p>

<p><strong>UPDATED CODE</strong></p>

<pre><code>    public boolean onItemLongClick(AdapterView&lt;?&gt; parent , View view , int position , long itemId ){
                EditText bar = (EditText)findViewById(R.id.search);
                String to = bar.getText().toString();
                ListView lv = (ListView) findViewById(R.id.downloads);
                String pos = lv.getItemAtPosition(position).toString();
                File filein = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() , pos);
                File fileTo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() , to);
                filein.renameTo(fileTo);
                finish();
                overridePendingTransition(0, 0);
                startActivity(getIntent());
                overridePendingTransition(0, 0);
                return true;
            }
        });
</code></pre>