convertView的疑问(软件管理器)

 package com.hixin.appexplorer;

 import java.util.List;

 import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView; public class MainActivity extends Activity { GridView gv;
private List<PackageInfo> packageInfos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.show_app_grid);
init();
gv=(GridView)this.findViewById(R.id.gv_apps);
gv.setAdapter(new GridViewAdapter(this)); }
private void init(){
packageInfos = getPackageManager().getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
}
class GridViewAdapter extends BaseAdapter{ LayoutInflater inflater;
public GridViewAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return packageInfos.size();
} @Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return packageInfos.get(position);
} @Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub View view = inflater.inflate(R.layout.gv_item, null);
TextView tv = (TextView)view.findViewById(R.id.gv_item_appname);
ImageView iv = (ImageView)view.findViewById(R.id.gv_item_icon);
tv.setText(packageInfos.get(position).packageName);
iv.setImageDrawable(packageInfos.get(position).applicationInfo.loadIcon(getPackageManager())); return view;
} }
}

其中getView函数没有用到,程序运行并没有问题

上一篇:java socket tcp(服务器循环检测)


下一篇:yii框架下使用redis