1 package com.hixin.appexplorer; 2 3 import java.util.List; 4 5 import android.app.Activity; 6 import android.content.Context; 7 import android.content.pm.PackageInfo; 8 import android.content.pm.PackageManager; 9 import android.os.Bundle; 10 import android.view.LayoutInflater; 11 import android.view.View; 12 import android.view.ViewGroup; 13 import android.view.Window; 14 import android.view.WindowManager; 15 import android.widget.BaseAdapter; 16 import android.widget.GridView; 17 import android.widget.ImageView; 18 import android.widget.TextView; 19 20 public class MainActivity extends Activity { 21 22 GridView gv; 23 private List<PackageInfo> packageInfos; 24 @Override 25 protected void onCreate(Bundle savedInstanceState) { 26 super.onCreate(savedInstanceState); 27 requestWindowFeature(Window.FEATURE_NO_TITLE); 28 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 29 setContentView(R.layout.show_app_grid); 30 init(); 31 gv=(GridView)this.findViewById(R.id.gv_apps); 32 gv.setAdapter(new GridViewAdapter(this)); 33 34 } 35 private void init(){ 36 packageInfos = getPackageManager().getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES); 37 } 38 class GridViewAdapter extends BaseAdapter{ 39 40 LayoutInflater inflater; 41 public GridViewAdapter(Context context) { 42 inflater = LayoutInflater.from(context); 43 } 44 @Override 45 public int getCount() { 46 // TODO Auto-generated method stub 47 return packageInfos.size(); 48 } 49 50 @Override 51 public Object getItem(int position) { 52 // TODO Auto-generated method stub 53 return packageInfos.get(position); 54 } 55 56 @Override 57 public long getItemId(int position) { 58 // TODO Auto-generated method stub 59 return position; 60 } 61 62 @Override 63 public View getView(int position, View convertView, ViewGroup parent) { 64 // TODO Auto-generated method stub 65 66 View view = inflater.inflate(R.layout.gv_item, null); 67 TextView tv = (TextView)view.findViewById(R.id.gv_item_appname); 68 ImageView iv = (ImageView)view.findViewById(R.id.gv_item_icon); 69 tv.setText(packageInfos.get(position).packageName); 70 iv.setImageDrawable(packageInfos.get(position).applicationInfo.loadIcon(getPackageManager())); 71 72 return view; 73 } 74 75 } 76 } 77 78
其中getView函数没有用到,程序运行并没有问题