我正在 Android 应用程序中创建一项功能,允许用户在仅包含应用程序图像的 GridView 中查看他们最近使用的 6 个应用程序。到目前为止我已经尝试过:
//Load recent used apps
ActivityManager result = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
ArrayList<RecentTaskInfo> apps = (ArrayList<RecentTaskInfo>) result.getRecentTasks(10, ActivityManager.RECENT_WITH_EXCLUDED);
ArrayAdapter adapter = new ArrayAdapter(MainActivity.this,
android.R.layout.simple_list_item_1, apps);
recentappsGridView.setAdapter(adapter);
但这仅在每一行和每一列中显示大量文本。我怎样才能解决这个问题/让它发生?请注意,我已经在同一 Activity 中使用 ListView 及其点击事件的方法。
最佳答案
创建ArrayAdapter
的子类。覆盖getView()
。将单元格设置为图像,而不是 TextView
。使用resolveActivityInfo()
on the Intent
您可以从 RecentTaskInfo
中的 baseIntent
获取 ActivityInfo
对象。使用 ActivityInfo
上的 icon
填充您的单元格。
我还没有尝试过那个食谱,但它应该会让你更接近。
关于java - 将最近的应用程序加载到 GridView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14653757/