私はアンドロイドで自分の音楽プレーヤーを作成する途中でした。いくつかの音楽ファイルをお気に入りに追加できるように、すべての音楽ファイルをギャラリーからフォルダーにロードしたくありません。しかし、問題は、ギャラリーからファイルを取得している間、それが繰り返されることです。すなわち。リストがフォルダーに 3 回または 4 回表示されます。論理エラーがないか確認していただけますか?? ありがとうございました :)
public ArrayList<String> getFromSdcard(String folderName)
{
ArrayList<String> audioFileLists = new ArrayList<String>();
File file= new File(folderName);
if (file.isDirectory())
{
File[] listFile = file.listFiles();//get list of files
for (int i = 0; i < listFile.length; i++)
{
String path = listFile[i].getAbsolutePath();
audioFileLists.add(path);//add path of files to array list
}
}
return audioFileLists;
}
private class MusicAdapter extends BaseAdapter {
private ArrayList<String> audioFile;
public MusicAdapter( ArrayList<String> audioFiles) {
audioFile = audioFiles;
}
public int getCount() {
return audioFile.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.gc();
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.musiclist, null);
TextView albumName = (TextView) convertView.findViewById(R.id.albumName);
String fileName = audioFile.get(position);
albumName.setText(fileName.substring(fileName.lastIndexOf("/")+1));
return convertView;
}
}
ViewHold を試した後の logcat を次に示します。
11-12 11:14:26.043: I/Ads(513): Request scenario: Online server request.
11-12 11:14:27.313: W/webcore(513): Can't get the viewWidth after the first layout
11-12 11:14:27.413: D/webviewglue(513): nativeDestroy view: 0x3053b8
11-12 11:14:27.423: I/Ads(513): onReceiveAd()
11-12 11:14:27.523: D/webviewglue(513): nativeDestroy view: 0x32d048
11-12 11:15:05.163: D/dalvikvm(513): GC_EXPLICIT freed 6162 objects / 466624 bytes in 111ms
11-12 11:28:53.443: D/dalvikvm(513): GC_FOR_MALLOC freed 20535 objects / 582840 bytes in 124ms
11-12 11:42:38.213: D/dalvikvm(513): GC_FOR_MALLOC freed 20821 objects / 523728 bytes in 117ms
11-12 11:56:20.473: D/dalvikvm(513): GC_FOR_MALLOC freed 20837 objects / 524536 bytes in 129ms