嗨,我正在做示例项目,因为我遇到了一个问题,比如 listitem 显示了一些垃圾值。不知道怎么解决。谁能帮我吗。
这是我的活动:
public class MainActivity extends Activity {
ListView app_List;
private ArrayList<AppInfo> infoList;
private ArrayAdapter<AppInfo> adpt;
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
app_List = (ListView)findViewById(R.id.listView1);
infoList = getListOfUserInstalledApps();
}
private ArrayList<AppInfo> getListOfUserInstalledApps() {
// TODO Auto-generated method stub
List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
System.out.println("No. of applications installed on the device: "+apps.size());
ArrayList<AppInfo> infoList1 = new ArrayList<AppInfo>();
for(int i=0;i<apps.size();i++) {
PackageInfo p = apps.get(i);
/*if ((!getSysPackages) && (p.versionName == null)) {
continue ; }*/
AppInfo info = new AppInfo();
//info.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
info.pname = p.packageName;
System.out.println("application name: "+info.pname);
//info.pname = p.packageName;
infoList1.add(info);
}
return infoList1;
}
static class AppInfo {
//private String appname = "";
private String pname = "";
//private String versionName = "";
//private int versionCode = 0;
//private Drawable icon;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
adpt = new ArrayAdapter<AppInfo>(this,android.R.layout.simple_list_item_1, infoList);
app_List.setAdapter(adpt);
}
}
参考屏幕截图