Here i am displaying all songs in on a listview ,i want to play that song based on onItemClick so suggest me how to do it based on my code here is my code to display list of audio files from SDcard
public class ListFileActivity extends ListActivity implements OnClickListener {
private String path;
MediaPlayer mda;
int current_index2 = 0;
String filename;
Button backToRecord, allvoices;
ToggleButton activateDelete;
ListView myList;
List values;
ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soundrecords);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
backToRecord = (Button) findViewById(R.id.buttonrecord);
activateDelete = (ToggleButton) findViewById(R.id.buttonedit);
allvoices = (Button) findViewById(R.id.buttoncontinuous);
myList = (ListView) findViewById(android.R.id.list);
backToRecord.setOnClickListener(this);
activateDelete.setOnClickListener(this);
allvoices.setOnClickListener(this);
// Use the current directory as title
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);
}