我的代码只能录制一个音频并显示列表视图,但我想在outfile和显示列表视图中录制更多音频。
OUTPUT_FILE=Environment.getExternalStorageDirectory()+"/" + name + ".3gpp";
Log.d("Files", "Path: " + OUTPUT_FILE);
File f = new File(OUTPUT_FILE);
myList = new ArrayList<String>();
myList.add(f.getName());
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, myList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
try
{
playRecording();
}
catch(Exception e)
{
e.printStackTrace();
}
}
});
最后我发现了问题,正确的代码如下所示:
myList = new ArrayList<String>();
file = new File( "/sdcard/"+name+"/");
file.mkdirs();
File list[] = file.listFiles();
for( int i=0; i< list.length; i++)
{
myList.add( list[i].getName() );
}
ListView listView = (ListView) findViewById(R.id.mylist);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, myList);
listView.setAdapter(adapter);