public class MainActivity extends Activity { private List<ResolveInfo> mApps = null; private ArrayList<HashMap<String, Object>> data = null; private HashMap<String, Object> hashMap = null; class ViewHolder { ImageView viewImg; TextView viewName; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); loadapp(); setContentView(R.layout.activity_main); GridView gridView = (GridView) findViewById(R.id.gridView1); BaseAdapter adapter = new BaseAdapter() { @Override public View getView(int position, View convertView, ViewGroup parent) { LinearLayout layout; ViewHolder holder = new ViewHolder(); if(convertView == null) { LayoutInflater inflater = getLayoutInflater(); layout = (LinearLayout) inflater.inflate(R.layout.linelayout, null); holder.viewImg = (ImageView) layout.findViewById(R.id.p_w_picpathView1); holder.viewName = (TextView) layout.findViewById(R.id.textView1); layout.setTag(holder); } else { layout = (LinearLayout) convertView; holder = (ViewHolder) layout.getTag(); } ResolveInfo info = mApps.get(position); holder.viewImg.setImageDrawable(info.activityInfo.loadIcon(getPackageManager())); holder.viewName.setText(info.activityInfo.loadLabel(getPackageManager()).toString()); return layout; } @Override public long getItemId(int position) { return position; } @Override public Object getItem(int position) { return mApps.get(position); } @Override public int getCount() { return mApps.size(); } }; gridView.setAdapter(adapter); } private void loadapp() { Intent intent = new Intent(Intent.ACTION_MAIN,null); intent.addCategory(Intent.CATEGORY_LAUNCHER); mApps = getPackageManager().queryIntentActivities(intent, 0); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
Android:GridView类似桌面显示所有应用
原创
©著作权归作者所有:来自51CTO博客作者glblong的原创作品,如需转载,请与作者联系,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章