importjava.util.List;importandroid.app.Activity;importandroid.content.Intent;importandroid.content.pm.ResolveInfo;importandroid.os.Bundle;importandroid.view.View;importandroid.view.ViewGroup;importandroid.widget.BaseAdapter;importandroid.widget.GridView;importandroid.widget.ImageView;public class MyHome extendsActivity
{
GridView mGrid;
@Overridepublic voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
loadApps();
setContentView(R.layout.main);
mGrid=(GridView) findViewById(R.id.apps_list);
mGrid.setAdapter(newAppsAdapter());
}private ListmApps;private voidloadApps() {
Intent mainIntent= new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mApps= getPackageManager().queryIntentActivities(mainIntent, 0);
}public class AppsAdapter extendsBaseAdapter
{publicAppsAdapter() { }public View getView(intposition, View convertView, ViewGroup parent) {
ImageView i;if (convertView == null) {
i= new ImageView(MyHome.this);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new GridView.LayoutParams(50, 50));
}else{
i=(ImageView) convertView;
}
ResolveInfo info=mApps.get(position);
i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));returni;
}public final intgetCount() {returnmApps.size();
}public final Object getItem(intposition) {returnmApps.get(position);
}public final long getItemId(intposition) {returnposition;
}
}
}