[Java for Android App Development] AmatuerAppDeveloper:
Hi, for the past hour or so, i have been trying to fix a problem and that problem is with the edit text part of my music player app...

Basically i have added a search function (EditText) to the music list of my app to allow people to search the songs from the list and then play the song, but it doesn't work, it just plays the wrong file when you click on it.

Now if you go to play a song without using the search then it'll work perfectly

Now as far as i can gather, it has something to do with the ' in.putExtra("songPath", songIndex); ' part of the click method, which again works perfectly fine when using the OnItemClick method but doesn't with the searches OnClick method

So that's where i need help... HOW DO I SEND THE FILES DATA PATH TO THE MUSIC PLAYER?

Here's the songs list activity which contains both the search and standard ListView:

import java.util.ArrayList;
import java.util.HashMap;

import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.simplistic.simplisticmusicfree.R;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Filterable;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class PlayListActivity extends ListActivity {

// Songs list
public ArrayList<HashMap<String,String>> songsList = new ArrayList<HashMap<String, String>>();
ListView musiclist;
Cursor mCursor;
int songTitle;
int count;
int songPath;
EditText songResult;
ArrayAdapter<String> adapter;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playlist);

ArrayList<HashMap<String, String>> songsListData = new ArrayList<HashMap<String, String>>();

SongsManager plm = new SongsManager();

// get all songs from sdcard
this.songsList = plm.getPlayList(this);

// looping through playlist
for (int i = 0; i < songsList.size(); i++) {
// creating new HashMap
HashMap<String, String> song = songsList.get(i);

// adding HashList to ArrayList
songsListData.add(song);

}

// Adding menuItems to ListView
final ListAdapter adapter = new SimpleAdapter(this, songsListData,
R.layout.playlist_item, new String[] { "songTitle", "songAlbum" }, new int[] {
R.id.songTitle, R.id.songAlbum});

setListAdapter(adapter);

final EditText songResult = (EditText) findViewById(R.id.inputSearch);
songResult.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {

Intent in = new Intent(getApplicationContext(),
MainActivity.class);
int songIndex = 0;
// Sending songIndex to PlayerActivity
in.putExtra("songPath", songIndex);
setResult(100, in);
// Closing PlayListView
finish();
}

});

songResult.addTextChangedListener(new TextWatcher() {

@Override
public void afterTextChanged(Editable arg0) {

}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
((Filterable) adapter).getFilter().filter(s);

}
});

// selecting single ListView item
ListView lv = getListView();

// listening to single listitem click
lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

// getting listitem index
int songIndex = position;
// Starting new intent
Intent in = new Intent(getApplicationContext(),
MainActivity.class);
Log.d("TAG","onItemClick");
// Sending songIndex to PlayerActivity
in.putExtra("songPath", songIndex);
setResult(100, in);
// Closing PlayListView
finish();

}
});

}

}

and here's the OnClicks result code:

@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == 100){
currentSongIndex = data.getExtras().getInt("songPath");
// play selected song
playSong(currentSongIndex);
}

}

public void playSong(int songIndex){

// Play song
try {
mp.reset();
mp.setDataSource(songsList.get(songIndex).get("songPath"));
mp.prepare();
mp.start();
shuffle();

// Displaying Song title
String songTitle = songsList.get(songIndex).get("songTitle");
songTitleLabel.setText(songTitle);

// Changing Button Image to pause image
btnPlay.setImageResource(R.drawable.img_btn_pause2);

// set Progress bar values
songProgressBar.setProgress(0);
songProgressBar.setMax(100);

// Updating progress bar
updateProgressBar();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

So yeah any solution would be grateful!

Thanks