I am having so much trouble with a block of code. I am searching for a listview with the list of installed applications name list. I have searched a lot. Later I have found some code. I don't know what is happening here. It just crush... Please don't laugh at my code.
listView = (ListView)findViewById(R.id.listView);
PackageManager packageManager = this.getPackageManager();
List<ApplicationInfo> appList = packageManager.getInstalledApplications(0);
List<String> myStrinrgArray = new ArrayList<String>();
Iterator<ApplicationInfo> it = appList.iterator();
while (it.hasNext()){
ApplicationInfo applicationInfo = (ApplicationInfo)it.next();
String appName = packageManager.getApplicationLabel(applicationInfo).toString();
myStrinrgArray.add(appName);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, myStrinrgArray);
listView.setAdapter(arrayAdapter);
}
Please help anyone if possible for you... I'll be glad at that.
NOTE: I have launched it in the emulator