码迷,mamicode.com
首页 > 其他好文 > 详细

daima

时间:2015-12-13 18:50:32      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

public class InstalledApplicationListActivity extends ListActivity implements OnItemClickListener{

    private List<String> mPackages = new ArrayList<String>();
   
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PackageManager packageManager = getPackageManager();
        List<PackageInfo> packageInfos = packageManager
                .getInstalledPackages(PackageManager.GET_ACTIVITIES);
       
        for(PackageInfo packageInfo : packageInfos) {
            mPackages.add(packageInfo.applicationInfo.loadLabel(packageManager)
                    + "\n" + packageInfo.packageName);
        }
       
       // ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, textViewResourceId)
        ArrayAdapter<String> arrayAdapter =
              new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, mPackages);
        setListAdapter(arrayAdapter);
        getListView().setOnItemClickListener(this);
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        Intent intent = new Intent();
        intent.putExtra("package_name", mPackages.get(position));
        setResult(1, intent);
        finish();
    }

daima

标签:

原文地址:http://www.cnblogs.com/zhangkefan/p/5043322.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!