1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
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.imageView1);
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
;
}
}
|
本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1218512,如需转载请自行联系原作者