Sunday, 18 August 2013

Open a new activity to play item on listitemclick

Open a new activity to play item on listitemclick

I have a list of files in a directory. In the activity shown below, the
app loads the files into a listview. Now, I need each list item to open
it's corresponding file in the directory and play the file in another
activity (probably via an intent). Even the test Toast notification does
not show up. How can I go about this?
public class ReadFilesFromPath extends Activity {
/** Called when the activity is first created. */
List<String> myList;
File file;
ListView listview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recordinglist);
listview = (ListView) findViewById(R.id.recordlist);
myList = new ArrayList<String>();
File directory = Environment.getExternalStorageDirectory();
file = new File( directory + "/" + "Recordify" );
File list[] = file.listFiles();
for( int i=0; i< list.length; i++)
{
myList.add( list[i].getName() );
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, myList);
listview.setAdapter(adapter); //Set all the file in the list.
}
public void onitemclick() {
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int i,
long l) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Test",
Toast.LENGTH_SHORT).show();
}
});
}
}

No comments:

Post a Comment