android:如何使用字符串[](已安装软件包的列表)填充微调器?
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);
final String[] apps = (String[]) pkgAppsList.toArray();
Spinner appSpinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> appAdapter = new ArrayAdapter(this, apps, android.R.layout.simple_spinner_item);
appAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
appSpinner.setAdapter(cloudAdapter);
前面的代码在 eclipse 中为我抛出错误。我了解如何获取已安装应用程序的列表,并且了解如何使用 createFromResource 方法填充微调器。但我从来没有尝试过以这种方式这样做?有人能指导我正确的方向吗?
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = this.getPackageManager().queryIntentActivities( mainIntent, 0);
final String[] apps = (String[]) pkgAppsList.toArray();
Spinner appSpinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> appAdapter = new ArrayAdapter(this, apps, android.R.layout.simple_spinner_item);
appAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
appSpinner.setAdapter(cloudAdapter);
The previous code is throwing out errors for me in eclipse. I understand how to get the list of installed apps, and I understand how to populate a spinner using the createFromResource method. However I've never attempted to do so in this manner? Anyone able to direct me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
values
文件夹中创建一个名为arrays.xml
的文件。在该给予:
然后在您的旋转器内,给予:
希望这对您有用。
Create a file named
arrays.xml
insidevalues
folder.Inside that give:
Then inside your spinner,give:
Hope this may work for you.
检查:如何获取已安装的 Android 应用程序列表并选择一个来运行
Check : How to get a list of installed android applications and pick one to run
即使已经晚了,您也应该使用 ArrayAdapter 的构造函数:
Eventough it is late, you should use this constructor of
ArrayAdapter
instead :