mp3 플레이어를 만들고 있는데요
거기서 앨범으로 듣기를 expandablelist를 이용해서
상위에 앨범명이 나오고 하위에 노래제목이 나오도록 하려는데요
현재 리스트로 mp3파일을 받아오는거까진 됩니다.
근데 expandablelist로 바꾸는 과정에서 자꾸 막히네요
계속 이것저것 시도해보는데두 계속막혀서...
아래는 리스트로 mp3파일을 받아오는 소스입니다.
요걸 expandablelist로 바꿔주려면 어느부분을 어떻게 고쳐야할지;;
public class AlbumTab extends ListActivity {
private ListView mTotalLV;
private ContentResolver mContentResolver;
private final String TAG = "AlbumTab";
private void init(){
//mTotalLV = (ListView) findViewById(R.id.totalListView);
mTotalLV = getListView();
mContentResolver = getContentResolver();
}
private void makeList(){
final ArrayList<MusicInfo> arrItems = new ArrayList<MusicInfo>();
Uri mp3URI = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri albumURI = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
String[] sMediaSelect = new String[]{ MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ALBUM_ID};
String[] sAlbumSelect = new String[]{ MediaStore.Audio.Albums._ID,
MediaStore.Audio.Albums.ALBUM_ART,
MediaStore.Audio.Albums.ALBUM};
Cursor totalCur = mContentResolver.query(mp3URI, sMediaSelect, null, null, null);
if(!totalCur.isFirst()) totalCur.moveToFirst();
int nAlbum_ID_Idx = totalCur.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);
int nAlbum_Idx = totalCur.getColumnIndex(MediaStore.Audio.Media.ALBUM);
int nTitle_Idx = totalCur.getColumnIndex(MediaStore.Audio.Media.TITLE);
int nArtist_Idx = totalCur.getColumnIndex(MediaStore.Audio.Media.ARTIST);
int nSongData_Idx = totalCur.getColumnIndex(MediaStore.Audio.Media.DATA);
while(!totalCur.isAfterLast())
{
Log.i(TAG, "album_art = " + totalCur.getString(nAlbum_ID_Idx));
Cursor albumCur = mContentResolver.query(albumURI,
sAlbumSelect,
"_id = " + totalCur.getString(nAlbum_ID_Idx),
null, null);
Log.i(TAG, "albumCur.getCount() = " + albumCur.getCount());
albumCur.moveToFirst();
// String title, String song_data, String artist,String album, String albumArt
MusicInfo musicItem = new MusicInfo(totalCur.getString(nTitle_Idx),
totalCur.getString(nSongData_Idx),
totalCur.getString(nArtist_Idx),
totalCur.getString(nAlbum_Idx),
albumCur.getString(albumCur.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART)));
arrItems.add(musicItem);
Log.i(TAG, "Titl = " + musicItem.getTitle() + " || SongData = " + musicItem.getSong_data() + " || artist = " + musicItem.getArtist() + " || album = " + musicItem.getAlbum() + " || album_art = " + musicItem.getAlbum_art());
totalCur.moveToNext();
};
mTotalLV.setAdapter(new AlbumArrayAdapter(this, R.layout.item, arrItems));
mTotalLV.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
Toast.makeText( getApplicationContext(),
"Position = " + position + " || getSong_data() = " + arrItems.get(position).getSong_data(),
Toast.LENGTH_SHORT)
.show();
}});
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.play_list);
init();
}
@Override
protected void onResume() {
super.onResume();
makeList();
//makeAlbumList();
}
public class CombineAdapter extends CursorAdapter{
private Cursor mCursor;
private Context mContext;
private int mLayoutResID;
public CombineAdapter(Context context, Cursor cursor) {
super(context, cursor);
this.mCursor = cursor;
this.mContext = context;
this.mLayoutResID = R.layout.item;
Log.i(TAG, "CombineAdapter()");
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
Log.i(TAG, "bindView()");
LinearLayout parentView = (LinearLayout) view;
String szTitle = mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String szArtist = mCursor.getString(mCursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
((TextView)view.findViewById(R.id.titleTXT)).setText(szTitle);
((TextView)view.findViewById(R.id.artistTXT)).setText(szArtist);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
Log.i(TAG, "newView()");
LayoutInflater inflater = LayoutInflater.from(context);
LinearLayout view = (LinearLayout) inflater.inflate(mLayoutResID, null);
return view;
}
public void removeFromMap(View view)
{
if(view != null)
{};
}
}
class AlbumAdapter extends SimpleCursorAdapter{
public AlbumAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
this.setViewBinder(new AlbumViewBinder());
}
}
public class AlbumViewBinder implements ViewBinder{
private final String TAG = "AlbumViewBinder";
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if(view instanceof LinearLayout)
{
if( ((LinearLayout)view).getId() == R.layout.item)
{
String szItems = cursor.getString(columnIndex);
if(szItems.length() >0)
{
//appendRowTextView((LinearLayout)view, )
}
}
}
return false;
}
}
public class AlbumArrayAdapter extends ArrayAdapter<MusicInfo>{
private Context mContext;
private int mLayoutResID;
private ArrayList<MusicInfo> mArrItems;
public AlbumArrayAdapter(Context context, int textViewResourceId, List<MusicInfo> objects) {
super(context, textViewResourceId, objects);
this.mArrItems = (ArrayList<MusicInfo>) objects;
this.mContext = context;
this.mLayoutResID = textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout view = (LinearLayout) convertView;
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = (LinearLayout) inflater.inflate(mLayoutResID, null);
//view = (RelativeLayout) inflater.inflate(mLayoutResID, null);
}
((TextView)view.findViewById(R.id.titleTXT)).setText(mArrItems.get(position).getTitle());
((TextView)view.findViewById(R.id.artistTXT)).setText( mArrItems.get(position).getArtist());
((ImageView)view.findViewById(R.id.albumImg)).setImageURI(Uri.parse(mArrItems.get(position).getAlbum_art()));
return view;
}
}
}