title: Display All Song From the SD card Genre Wise
body: <p>I am Doing Musicplayer Application. and want to show All the Songs with respect to its Genre. if possible then please give me some hint for that. i able to display all the Song With Respect to Artist and Album but Facing Problem While Going For Genre Wise Song. my out put is displaying all the Songs in Each genre catagory. it is not saprating the Song According to genre. Mycode is Below. 
  LocalGenre.java</p>
  
  <pre><code>package com.PageViewerTilesDemo.src;
  
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.database.Cursor;
  import android.graphics.Bitmap;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.util.Log;
  import android.view.Window;
  import android.widget.ExpandableListView;
  import android.widget.TextView;
  
  public class LocanGenre extends Activity {
  
      ExpandableListView listLocalArtists;
      TextView txttitle;
      Cursor musiccursor, musiccursor1;
      int music_column_index, music_column_index1;
      int count, count1;
  
      ArrayList&lt;String&gt; genresName = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; genreID = new ArrayList&lt;String&gt;();
      ArrayList&lt;Integer&gt; albumID = new ArrayList&lt;Integer&gt;();
      ArrayList&lt;String&gt; numberOFSongs = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; artistName = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; path = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; path12 = new ArrayList&lt;String&gt;();
      ArrayList&lt;ArrayList&lt;String&gt;&gt; pathDisplay = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.localartists);
  
          txttitle = (TextView) findViewById(R.id.title);
  
          txttitle.setText("Genres");
  
          listLocalArtists = (ExpandableListView) findViewById(R.id.listView1);
  
          init_phone_music_grid();
  
          listLocalArtists.setAdapter(new ExpandableListGenreAdapter(this, path, genresName,
                  genresName, pathDisplay,albumID));
      }
  
      private void init_phone_music_grid() {
          // TODO Auto-generated method stub
  
          System.gc();
  
          String[] proj = {
                  MediaStore.Audio.Media._ID,
                  MediaStore.Audio.Media.DISPLAY_NAME,
                  MediaStore.Audio.Media.ALBUM_ID};
  
          musiccursor1 = managedQuery(
                  MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, null,
                  null);
  
          count1 = musiccursor1.getCount();
  
          if (count1 &gt; 0) {
              musiccursor1.moveToFirst();
              do {
  
                  music_column_index1 = musiccursor1
                          .getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
  
                  String filename0 = musiccursor1.getString(music_column_index1);
                  path.add(filename0);
  
                  Log.i("LocalGenres  ", "Path  Main" + path);
  
                  music_column_index1 = musiccursor1
                          .getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
  
                  String filename123 = musiccursor1
                          .getString(music_column_index1);
                  path12.add(filename123);
  
                  Log.i("LocalGenre", "Media ID  " + path12);
  
                  music_column_index1 = musiccursor1
                          .getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);
  
                  int filename1 = musiccursor1.getInt(music_column_index1);
  
  
                  albumID.add(filename1);
                  Log.i("LOCAL Genres!!!", " ALBUM ID" + albumID);
  
  
              } while (musiccursor1.moveToNext());
          }
  
          String[] projection = { MediaStore.Audio.Genres._ID,
                  MediaStore.Audio.Genres.NAME};
  
          musiccursor = managedQuery(
                  MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, projection, null,
                  null, null);
  
          genresName.clear();
  
          count = musiccursor.getCount();
  
          if (count &gt; 0) {
              musiccursor.moveToFirst();
              do {
  
                  music_column_index = musiccursor
                          .getColumnIndexOrThrow(MediaStore.Audio.Genres._ID);
  
                  String filename = musiccursor.getString(music_column_index);
                  if(!genreID.contains(filename))
                  {
                  genreID.add(filename);
                  }
  
                  Log.i("Local Genres  ", "Genre ID" + genreID);
  
                  music_column_index = musiccursor
                          .getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME);
  
                  String filename1 = musiccursor.getString(music_column_index);
                  if(!genresName.contains(filename1))
                  {
                  genresName.add(filename1);
                  }
  
                  Log.i("Local Genres  ", "Genres Name  " + genresName);
  
                  /*
                   * music_column_index = musiccursor
                   * .getColumnIndexOrThrow(MediaStore.Audio.Genres._COUNT);
                   * 
                   * String filename3 = musiccursor.getString(music_column_index);
                   * artistName.add(filename3);
                   * 
                   * Log.i("Local Albums  ", "Album ID for Gen  " + artistName);
                   */
  
              } while (musiccursor.moveToNext());
          }
  
          for (int j = 0; j &lt; genreID.size(); j++) {
  
              ArrayList&lt;String&gt; arr = new ArrayList&lt;String&gt;();
  
              for (int i = 0; i &lt; path12.size(); i++) {
                  Log.i("EEEEEE", "Inside If path12.get(i) :"+path12.get(i));
                  Log.i("EEEEEE", "Inside If genreID.get(j) :"+genreID.get(j));
                  Log.i("EEEEEE", "Inside If Integer.parseInt(path12.get(i)) :"+Integer.parseInt(path12.get(i)));
                  Log.i("EEEEEE", "Inside If j : "+j);
                  if (path12.get(i).equalsIgnoreCase(genreID.get(j)) || Integer.parseInt(path12.get(i))&gt;j) {
  
                      Log.i("EEEEEE", "Inside If");
                      arr.add(path.get(i));
                  }
  
                  else
                      Log.i("xxxxxxx", "Inside else");
                  arr.add(path.get(i));
              }
  
              Log.i("EEEEEE", "Inside outerloop " + arr);
  
              pathDisplay.add(arr);
          }
      }
  }
  </code></pre>
  
  <p>ExpandableListGenreAdapter.java</p>
  
  <pre><code>    package com.PageViewerTilesDemo.src;
  
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Context;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.View.OnClickListener;
  import android.widget.BaseExpandableListAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  public class ExpandableListGenreAdapter  extends BaseExpandableListAdapter{
  
      private Context context;
  
      private ArrayList&lt;String&gt; artist;
  
      private ArrayList&lt;String&gt; genres;
  
      private ArrayList&lt;ArrayList&lt;String&gt;&gt; children;
  
      public ArrayList&lt;String&gt; pathmain ;
  
      public ArrayList&lt;Integer&gt; genresID;
  
      public ArrayList&lt;Integer&gt; albumID;
  
      public ExpandableListGenreAdapter(Context context, ArrayList&lt;String&gt; path, ArrayList&lt;String&gt; groups,ArrayList&lt;String&gt; artist,
              ArrayList&lt;ArrayList&lt;String&gt;&gt; children, ArrayList&lt;Integer&gt; albumID) {
          this.context = context;
          this.genres = groups;
          this.artist = artist;
          this.pathmain = path;
          this.children = children;
          this.albumID=albumID;
      }
  
      @Override
      public Object getChild(int groupPosition, int childPosition) {
          // TODO Auto-generated method stub
          return children.get(groupPosition).get(childPosition);
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition) {
          // TODO Auto-generated method stub
          return childPosition;
      }
  
      /*public Bitmap getAlbumart(int album_id) 
         {
              Bitmap bm = null;
              try 
              {
                  final Uri sArtworkUri = Uri
                      .parse("content://media/external/audio/albumart");
  
                  Uri uri = ContentUris.withAppendedId(sArtworkUri, album_id);
  
                  ParcelFileDescriptor pfd = context.getContentResolver()
                      .openFileDescriptor(uri, "r");
  
                  if (pfd != null) 
                  {
                      FileDescriptor fd = pfd.getFileDescriptor();
                      bm = BitmapFactory.decodeFileDescriptor(fd);
                  }
          } catch (Exception e) {
          }
          return bm;
      }*/
  
      @Override
      public View getChildView(final int groupPosition, final int childPosition,
              boolean isLastChild, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          final String vehicle = (String) getChild(groupPosition, childPosition);
  
          Log.i("ExpandableListAdapter", "Group Position  "+groupPosition);
  
          Log.i("ExpandableListAdapter", "Vehicle  "+vehicle);
  
          if (convertView == null) {
              LayoutInflater infalInflater = (LayoutInflater) context
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              convertView = infalInflater.inflate(R.layout.child_layout, null);
          }
  
          TextView tv = (TextView) convertView.findViewById(R.id.tvChild);
          ImageView imageview1=(ImageView)convertView.findViewById(R.id.ImageView01);
     //     bm=getAlbumart(albumids.get(1));
         // Log.i("LIST ADAPTER","@@@@@@@@@@@@@@@@@@@ALBUM IDS "+albumids.get(0)+"BITMAPPPPP@@@"+bm);
  
         // imageview1.setImageBitmap(coverart.get(childPosition));
          tv.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
  
                  MainActivity.flag = true;
  
                  TestFragment3.flag = true;
  
                  Firstpage.flag = true;
  
                  Log.i("ExpandableListGenreAdapter", "path  "+childPosition);
  
                  MainActivity.currentPosition = groupPosition;
  
                  Log.i("ExpandableListGenreAdapter", "currentPosition  "+MainActivity.currentPosition);
  
                  MainActivity.genre=true;
                  MainActivity.currentgenreposition = albumID.get(childPosition);
  
                  Log.i("ExpandableListGenreAdapter", "currentGenrePosition  "+MainActivity.currentgenreposition);
  
                  MainActivity.Media_full_path = "/sdcard/"+vehicle;
  
                  Log.i("ExpandableListAdapter", "Onclick  "+MainActivity.Media_full_path);
  
                  ((Activity)context).finish();
  
  
              }
          });
  
          tv.setText("   " + vehicle.toString());
  
          return convertView;
      }
  
      @Override
      public int getChildrenCount(int groupPosition) {
          // TODO Auto-generated method stub
          return children.get(groupPosition).size();
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          // TODO Auto-generated method stub
          return genres.get(groupPosition);
      }
  
      @Override
      public int getGroupCount() {
          // TODO Auto-generated method stub
          return genres.size();
      }
  
      @Override
      public long getGroupId(int groupPosition) {
          // TODO Auto-generated method stub
          return groupPosition;
      }
  
      @Override
      public View getGroupView(int groupPosition, boolean isExpanded,
              View convertView, ViewGroup parent) {
           String group = (String) getGroup(groupPosition);
              if (convertView == null) {
                  LayoutInflater infalInflater = (LayoutInflater) context
                          .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  convertView = infalInflater.inflate(R.layout.group_layout, null);
              }
              TextView txtArtistsName = (TextView) convertView.findViewById(R.id.txtArtistsName);
              TextView txtartistssongs = (TextView) convertView.findViewById(R.id.txtartistssongs);
              txtArtistsName.setText(group);
              txtartistssongs.setText(genres.get(groupPosition)+" Song(s)");
              return convertView;
      }
  
      @Override
      public boolean hasStableIds() {
          // TODO Auto-generated method stub
          return true;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          // TODO Auto-generated method stub
          return true;
      }
  
  }
  </code></pre>
  
  <p>Please Suggest me Where is i am missing from the Above Code. Thank You.</p>