public class MainActivity extends Activity {
private GridView gr;
R.drawable.widget06,R.drawable.widget07,R.drawable.widget08,R.drawable.widget09,};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gr = (GridView) findViewById(R.id.gv);
adapter = new MainAdapter(this,mz ,wj);
gr.setAdapter(adapter);
}
public class MainAdapter extends BaseAdapter{
private Context context;
private String[] namel;
private int[] icon;
public MainAdapter(Context context,String[] mz, int[] wj) {
// TODO Auto-generated constructor stub
this.namel = mz;
this.icon = wj;
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return namel.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return namel[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Voidwhouder hoder = null;
if(convertView == null){
hoder = new Voidwhouder();
convertView = View.inflate(context, R.layout.mina, null);
hoder.da = (ImageView) convertView.findViewById(R.id.im);
hoder.tx = (TextView) convertView.findViewById(R.id.lll);
convertView.setTag(hoder);
}else{
hoder = (Voidwhouder) convertView.getTag();
}
hoder.da.setImageResource(icon[position]);
hoder.tx.setText(namel[position]);
return convertView;
}
class Voidwhouder{
ImageView da;
TextView tx;
<style name="maystyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">20dp</item>
<item name="android:drawableLeft">@android:drawable/star_big_on</item>
</style>
<style
name="sxing">
<item name="android:textColor">#ff0000</item>
TextView
style="@style/maystyle"
android:text="sim卡变更报警"
/>
<TextView
style="@style/maystyle"
android:text="Gps追踪"
/>
<TextView
style="@style/maystyle"
android:text="远程成销毁数据"
/>
<TextView
style="@style/maystyle"
android:text="远程锁屏"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Animation"
android:text="远程锁屏"
/>
</LinearLayout>
public class MainActivity extends Activity {
private ListView lv;
private List<AppInfo> list;
private dapt baser;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
* 得到手机中所有应用信息的列表
* AppInfo
* Drawable icon
* String appName
* String packageName
*/
lv=(ListView) findViewById(R.id.lv);
list = getAllAppInfos();
baser = new dapt();
lv.setAdapter(baser);
//给Listview添加点击监听
lv.setOnItemClickListener( new OnItemClickListener() {
//parent 是listview
//view 当前itm试图对象
//position 当前行的下标
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
//获取当前应用的名称
String name = list.get(position).getAppName();
//提示
Toast.makeText(getApplicationContext(), name+"", 2).show();
}
});
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
//删除当前行
//删除当前行的数据
list.remove(position);
//更新列表
baser.notifyDataSetChanged();//通知适配器更新列表
return true;
}
});
}
protected List<AppInfo> getAllAppInfos() {
List<AppInfo> list = new ArrayList<AppInfo>();
// 得到应用的packgeManager
PackageManager packageManager = getPackageManager();
// 创建一个主界面的intent
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// 得到包含应用信息的列表
List<ResolveInfo> ResolveInfos = packageManager.queryIntentActivities(
intent, 0);
// 遍历
for (ResolveInfo ri : ResolveInfos) {
// 得到包名
String packageName = ri.activityInfo.packageName;
// 得到图标
Drawable icon = ri.loadIcon(packageManager);
// 得到应用名称
String appName = ri.loadLabel(packageManager).toString();
// 封装应用信息对象
AppInfo appInfo = new AppInfo(icon, appName, packageName);
// 添加到list
list.add(appInfo);
}
return list;
}
class dapt extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.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) {
Viewhoder ho = null;
if(convertView == null){
ho = new Viewhoder();
convertView = View.inflate(MainActivity.this, R.layout.lv, null);
ho.im = (ImageView) convertView.findViewById(R.id.imageView1);
ho.tx = (TextView) convertView.findViewById(R.id.textView1);
convertView.setTag(ho);
}else{
ho = (Viewhoder) convertView.getTag();
}
AppInfo app = list.get(position);
ho.im.setImageDrawable(app.getIcon());
ho.tx.setText(app.getAppName());
return convertView;
}
class Viewhoder{
ImageView im;
TextView tx;
}
}
}
private GridView gr;
private MainAdapter adapter;
privite String[] mz = new String[]{"放在","通讯","app","打","启动","尺寸","地","大","cc"};privateint[]wj=newint[]{R.drawable.widget01,R.drawable.widget02,R.drawable.widget03,R.drawable.widget04,R.drawable.widget05,R.drawable.widget06,R.drawable.widget07,R.drawable.widget08,R.drawable.widget09,};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gr = (GridView) findViewById(R.id.gv);
adapter = new MainAdapter(this,mz ,wj);
gr.setAdapter(adapter);
}
public class MainAdapter extends BaseAdapter{
private Context context;
private String[] namel;
private int[] icon;
public MainAdapter(Context context,String[] mz, int[] wj) {
// TODO Auto-generated constructor stub
this.namel = mz;
this.icon = wj;
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return namel.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return namel[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Voidwhouder hoder = null;
if(convertView == null){
hoder = new Voidwhouder();
convertView = View.inflate(context, R.layout.mina, null);
hoder.da = (ImageView) convertView.findViewById(R.id.im);
hoder.tx = (TextView) convertView.findViewById(R.id.lll);
convertView.setTag(hoder);
}else{
hoder = (Voidwhouder) convertView.getTag();
}
hoder.da.setImageResource(icon[position]);
hoder.tx.setText(namel[position]);
return convertView;
}
class Voidwhouder{
ImageView da;
TextView tx;
<style name="maystyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textSize">20dp</item>
<item name="android:drawableLeft">@android:drawable/star_big_on</item>
</style>
<style
name="sxing">
<item name="android:textColor">#ff0000</item>
TextView
style="@style/maystyle"
android:text="sim卡变更报警"
/>
<TextView
style="@style/maystyle"
android:text="Gps追踪"
/>
<TextView
style="@style/maystyle"
android:text="远程成销毁数据"
/>
<TextView
style="@style/maystyle"
android:text="远程锁屏"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Animation"
android:text="远程锁屏"
/>
</LinearLayout>
public class MainActivity extends Activity {
private ListView lv;
private List<AppInfo> list;
private dapt baser;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*
* 得到手机中所有应用信息的列表
* AppInfo
* Drawable icon
* String appName
* String packageName
*/
lv=(ListView) findViewById(R.id.lv);
list = getAllAppInfos();
baser = new dapt();
lv.setAdapter(baser);
//给Listview添加点击监听
lv.setOnItemClickListener( new OnItemClickListener() {
//parent 是listview
//view 当前itm试图对象
//position 当前行的下标
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
//获取当前应用的名称
String name = list.get(position).getAppName();
//提示
Toast.makeText(getApplicationContext(), name+"", 2).show();
}
});
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
//删除当前行
//删除当前行的数据
list.remove(position);
//更新列表
baser.notifyDataSetChanged();//通知适配器更新列表
return true;
}
});
}
protected List<AppInfo> getAllAppInfos() {
List<AppInfo> list = new ArrayList<AppInfo>();
// 得到应用的packgeManager
PackageManager packageManager = getPackageManager();
// 创建一个主界面的intent
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
// 得到包含应用信息的列表
List<ResolveInfo> ResolveInfos = packageManager.queryIntentActivities(
intent, 0);
// 遍历
for (ResolveInfo ri : ResolveInfos) {
// 得到包名
String packageName = ri.activityInfo.packageName;
// 得到图标
Drawable icon = ri.loadIcon(packageManager);
// 得到应用名称
String appName = ri.loadLabel(packageManager).toString();
// 封装应用信息对象
AppInfo appInfo = new AppInfo(icon, appName, packageName);
// 添加到list
list.add(appInfo);
}
return list;
}
class dapt extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.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) {
Viewhoder ho = null;
if(convertView == null){
ho = new Viewhoder();
convertView = View.inflate(MainActivity.this, R.layout.lv, null);
ho.im = (ImageView) convertView.findViewById(R.id.imageView1);
ho.tx = (TextView) convertView.findViewById(R.id.textView1);
convertView.setTag(ho);
}else{
ho = (Viewhoder) convertView.getTag();
}
AppInfo app = list.get(position);
ho.im.setImageDrawable(app.getIcon());
ho.tx.setText(app.getAppName());
return convertView;
}
class Viewhoder{
ImageView im;
TextView tx;
}
}
}