0

帮助!都是一样的黑屏。显示需要添加代码。谢谢。我使用这样的代码:

package com.tipfile;

import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;


public class dop extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dop);
    PackageManager pm = this.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) 
    pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
    for (ResolveInfo rInfo : list) {
    System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
    }
    ListView listView = (ListView) findViewById(R.id.list);
    ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
    listView.setAdapter(aa);
}}
4

2 回答 2

2
  ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
    listView.setAdapter(aa);

您没有使用任何数据进行初始化aa,因此会出现黑屏。

您可以从ArrayAdapter 构造函数List<String>构建变量 ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>)并使用该构造函数接受要填充的列表aa

编辑

List<String> myList = new ArrayList<String>();
ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
    System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
myList.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}

ListView listView = (ListView) findViewById(R.id.list);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, myList);
listView.setAdapter(aa);
于 2011-05-16T10:48:48.487 回答
0
ArrayAdapter<String> aa = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);

将这些行更改为

ArrayAdapter<String> aa = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
于 2011-05-16T11:04:55.880 回答