tags:

views:

32

answers:

0

Hello,

I am working on an album art list using the build in MediaStore database. I am having trouble figuring out how to pass a String from the OnClick method to the intent. I want to pass the chosen album title to the next activity. Here is my code:

import android.app.Activity;

import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; import android.widget.ListAdapter; import android.widget.SimpleCursorAdapter; import android.widget.Toast;

public class CoverMenu extends Activity {

public String artist;

private Cursor c;

    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
         Bundle data = this.getIntent().getExtras();
         this.artist = data.getString("artistPass");
            Toast.makeText(this, artist, Toast.LENGTH_LONG).show();


             setContentView(R.layout.album_grid);

            GridView g = (GridView) findViewById(R.id.myGrid);
            g.setAdapter(new ImageAdapter(this, getContentResolver())); 




    }




  // Toast.makeText(this, artistKey, Toast.LENGTH_LONG).show();

    public class ImageAdapter extends BaseAdapter {
            //private MediaStore.Images.Media msim;
            private ContentResolver mCr;
            String[] projection = new String[] {
                   MediaStore.Audio.Albums._ID,
                   MediaStore.Audio.Albums.ALBUM,
                   MediaStore.Audio.Albums.ALBUM_ART,
                   MediaStore.Audio.Albums.ARTIST,


                };




            public ImageAdapter(Context c, ContentResolver cr) {
                    mContext = c;
                    mCr = cr;
            }

            public int getCount() {
                    // Make uri a local member?  Performance?
                    Cursor c = managedQuery(android.provider.MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,null,null,null,null);
                    return c.getCount();
                    //return mThumbIds.length;
            }

            public Object getItem(int position) {
                    return position;
            }

            public long getItemId(int position) {
                    return position;
            }

            public View getView(final int position, View convertView, ViewGroup parent) {
                    ImageView imageView = new ImageView(mContext);



                    if (convertView == null) {
                            imageView = new ImageView(mContext);
                            imageView.setLayoutParams(new GridView.LayoutParams(250, 250));
                            imageView.setAdjustViewBounds(false);
                            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                            imageView.setPadding(8, 8, 8, 8);
                    } else {
                            imageView = (ImageView) convertView;
                    }


                     imageView.setOnClickListener(new View.OnClickListener()
                    {

  @Override
                      public void onClick(View view) 
                      {





   Intent i = new Intent(mContext ,ListSong.class);

    Bundle data = new Bundle();

    data.putString("albumPass",

// WHAT DO I DO HERE? ); i.putExtras(data); startActivity(i);

                                   }
                            });


                    Cursor c = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[] 
                          {MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ARTIST, MediaStore.Audio.Albums.ALBUM, 
                          MediaStore.Audio.Albums.ALBUM_ART}, MediaStore.Audio.Albums.ARTIST + "='" + artist + "'", null,  null);
                    Log.i("Cover", artist);
                    c.moveToPosition(position);
                    int dataCol = c.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART); 
                    int albumId = c.getColumnIndex(MediaStore.Audio.Albums.ALBUM);

                    if (dataCol == 0){


                    }else {
                    String data = c.getString(dataCol);

                    Uri dataURI = Uri.parse(data);  
                    imageView.setImageURI(dataURI);

                    imageView.setId(albumId);





                    }
                    return imageView;
            }

            private Context mContext;


    }

}