안드로이드..

ExpandableList 예제를 이용해서 만들어봤는데요

예제에서는 값을 상위 가수 하위 곡명 이런식으로 만들었는데

mp3에 사용하려면 mp3파일을 가져와야하잖아요

그걸 적용시키는게 잘안되네요..





public class ExpandableListExam extends ExpandableListActivity {

    ExpandableListAdapter mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set up our adapter
        mAdapter = new MyExpandableListAdapter();
        setListAdapter(mAdapter);
        registerForContextMenu(getExpandableListView());
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        menu.setHeaderTitle("Sample menu");
        menu.add(0, 0, 0, R.string.expandable_list_sample_action);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

        String title = ((TextView) info.targetView).getText().toString();

        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);  
            int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);  
            Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
                    Toast.LENGTH_SHORT).show();
            return true;
        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);  
            Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
            return true;
        }

        return false;
    }


    
    public class MyExpandableListAdapter extends BaseExpandableListAdapter {
        private String[] groups = { "다비치", "아이유", "티아라", "소녀시대", "싸이", "브라운아이드걸스" };
        private String[][] children = {
                { "두 번 헤어지는 일", "시간아 멈춰라", "8282", "미워도 사랑하니까", "난 너에게" },
                { "잔소리", "사랑을 믿어요", "있잖아", "Boo", "여자라서" },
                { "Bo Peep Bo Peep", "너 때문에 미쳐", "처음처럼", "거짓말", "TTL" },
                { "소원을 말해봐", "Gee", "Oh!", "다시 만난 세계", "Kissing you" },
                { "챔피언", "낙원", "내 눈에는", "새", "Thank you" },
                { "어쩌다", "Second", "Abracadabra", "Sign", "Candy Man" },
        };

        public Object getChild(int groupPosition, int childPosition) {
            return children[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

        public int getChildrenCount(int groupPosition) {
            return children[groupPosition].length;
        }

        public TextView getGenericView() {
            // 리스트 높이조절
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT, 40);

            TextView textView = new TextView(ExpandableListExam.this);
            textView.setLayoutParams(lp);
            // Center the text vertically
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
            // Set the text starting position
            textView.setPadding(36, 0, 0, 0);
            return textView;
        }

        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                View convertView, ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getChild(groupPosition, childPosition).toString());
            return textView;
        }

        public Object getGroup(int groupPosition) {
            return groups[groupPosition];
        }

        public int getGroupCount() {
            return groups.length;
        }

        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                ViewGroup parent) {
            TextView textView = getGenericView();
            textView.setText(getGroup(groupPosition).toString());
            return textView;
        }

        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }

        public boolean hasStableIds() {
            return true;
        }

    }
}



요기까지  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;
  }
  
}
}