Android相册艺术GridView
我是Android开发的新手,我正在开发一款媒体播放器应用程序作为学习体验。我目前正在尝试添加一个菜单视图,它在gridview中利用相册艺术。这是我的密码:Android相册艺术GridView,android,gridview,Android,Gridview,我是Android开发的新手,我正在开发一款媒体播放器应用程序作为学习体验。我目前正在尝试添加一个菜单视图,它在gridview中利用相册艺术。这是我的密码: public class coverMenu extends Activity { private Cursor audioCursor; public String artistInput; private static final String TAG = "coverMenu"; @Override public vo
public class coverMenu extends Activity {
private Cursor audioCursor;
public String artistInput;
private static final String TAG = "coverMenu";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cover);
Bundle data = this.getIntent().getExtras();
String artistKey = data.getString("artistPass");
Toast.makeText(this, artistKey, Toast.LENGTH_LONG).show();
audioCursor = getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null,
MediaStore.Audio.Albums.ARTIST + "='" + artistKey + "'", null,MediaStore.Audio.Albums.ALBUM + " ASC");
startManagingCursor(audioCursor);
String[]from = new String[]{MediaStore.Audio.Albums.ALBUM_ART};
int[] to = new int []{android.R.id.text1};
ListAdapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1,
audioCursor, from, to);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(mAdapter);
我的问题是网格项现在列出了艺术的路径,但没有显示它。有人能帮我解释一下如何将其解析为位图并发送到gridview吗
我花了一些时间研究Android音乐播放器的股票,但找不到一个简单的解决方案
感谢您的帮助
[最新调试:]
DalvikVM[localhost:8615]
Thread [<3> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2496
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2512
ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 119
ActivityThread$H.handleMessage(Message) line: 1863
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4363
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]
Thread [<13> Binder Thread #2] (Running)
Thread [<11> Binder Thread #1] (Running)
Thread [<15> Binder Thread #3] (Running)
DalvikVM[localhost:8615]
线程[main](挂起(异常运行时异常))
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord,Intent)行:2496
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord,Intent)行:2512
ActivityThread.access$2200(ActivityThread,ActivityThread$ActivityRecord,Intent)行:119
ActivityThread$H.handleMessage(消息)行:1863
ActivityThread$H(处理程序)。dispatchMessage(消息)行:99
Looper.loop()行:123
ActivityThread.main(字符串[])行:4363
invokenactive(Object,Object[],Class,Class[],Class,int,boolean)行:不可用[本机方法]
调用(对象,对象…)行:521
ZygoteInit$MethodAndArgsCaller.run()行:860
颧骨单位。主(字符串[])行:618
NativeStart.main(字符串[])行:不可用[本机方法]
螺纹[活页夹螺纹#2](运行)
螺纹[活页夹螺纹#1](运行)
螺纹[活页夹螺纹#3](运行)
您需要创建一个自定义适配器类,该类根据光标的位置返回填充的网格视图项。这里有一个相当粗糙的例子
自定义_grid_item.xml:
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="@+id/album_image"
android:layout_height="wrap_content" android:layout_width="wrap_content">
</ImageView>
</LinearLayout>
活动:
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.GridView;
import android.widget.Toast;
public class CoverMenu extends Activity {
private Cursor audioCursor;
public String artistInput;
private static final String TAG = "coverMenu";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set to some artist you know
String artistKey = "Devo";
Toast.makeText(this, artistKey, Toast.LENGTH_LONG).show();
audioCursor = getContentResolver().query(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null,
MediaStore.Audio.Albums.ARTIST + "='" + artistKey + "'", null,
MediaStore.Audio.Albums.ALBUM + " ASC");
startManagingCursor(audioCursor);
String[] from = new String[] { MediaStore.Audio.Albums.ALBUM_ART };
int[] to = new int[] { android.R.id.text1 };
MySimpleListAdapter mAdapter = new MySimpleListAdapter(this,
android.R.layout.simple_list_item_1, audioCursor, from, to);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(mAdapter);
}}
请从中查看这段精彩的视频,它将在将来对您有很大帮助。单击导致主活动的“艺术家”列表时捕捉强制关闭。线程[main](挂起(异常运行时异常))活动线程。性能启动活动(活动线程$ActivityRecord,意图)行:2496 ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord,Intent)行:2512 ActivityThread.access$2200(ActivityThread,ActivityThread$ActivityRecord,Intent)行:119 ActivityThread$H.handleMessage(Message)行:1863 ActivityThread$H(Handler)。dispatchMessage(Message)行:99 loop.loop()行:123 ActivityThread.main(String[])行:4363方法。invokenactive(Object,Object[],Class,Class[],Class,int,boolean)行:不可用[native Method]方法。invoke(Object,Object…)行:521 ZygoteInit$MethodAndArgsCaller.run()行:860 ZygoteInit.main(String[])行:618 nativestar.main(String[])行:不可用[native method]谢谢你的帮助。我不是有意回复,也似乎不太感激。没关系,Josh。我在Nexus One上测试了我的,我没有使用任何意图捆绑包,我只是补充了一点,希望你能解决这个问题。我会将它修复到我的(工作)版本。
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.widget.GridView;
import android.widget.Toast;
public class CoverMenu extends Activity {
private Cursor audioCursor;
public String artistInput;
private static final String TAG = "coverMenu";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set to some artist you know
String artistKey = "Devo";
Toast.makeText(this, artistKey, Toast.LENGTH_LONG).show();
audioCursor = getContentResolver().query(
MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null,
MediaStore.Audio.Albums.ARTIST + "='" + artistKey + "'", null,
MediaStore.Audio.Albums.ALBUM + " ASC");
startManagingCursor(audioCursor);
String[] from = new String[] { MediaStore.Audio.Albums.ALBUM_ART };
int[] to = new int[] { android.R.id.text1 };
MySimpleListAdapter mAdapter = new MySimpleListAdapter(this,
android.R.layout.simple_list_item_1, audioCursor, from, to);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(mAdapter);
}}