0

我正在尝试使用以下代码获取已安装应用程序图标的列表,但是它仅显示可绘制路径的列表,但不显示图标(即 android.graphics.drawable.BitmapDrawable@417530c8),

有人可以告诉我我做错了什么。

谢谢

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView appList = (ListView) findViewById(R.id.appList);

    ArrayList<Drawable> cacheArrayList = new ArrayList<Drawable>();

    ArrayAdapter<Drawable> aa = new ArrayAdapter<Drawable>(this,
            android.R.layout.simple_list_item_1, cacheArrayList);

    appList.setAdapter(aa);

    PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm
            .getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo packageInfo : packages) {
        // cacheArrayList.add((String) packageInfo.loadLabel(pm));
        cacheArrayList.add(packageInfo.loadIcon(pm));

    }

}

}

4

1 回答 1

0

默认情况下,ArrayAdapter只调用toString底层数组的每个元素。要同时使用 an ImageView,您需要编写一个ArrayAdapter覆盖该getView方法的子类。使用包含 的布局ImageView,然后对其进行覆盖getView调用,从数组setImageDrawable中传递。Drawable

于 2013-07-01T08:36:39.203 回答