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

listView加载在Dialog里面

时间:2014-06-06 23:20:38      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
        LinearLayout linearLayoutMain = new LinearLayout(this);// 自定义一个布局文件
        linearLayoutMain.setLayoutParams(new LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        ListView listView = new ListView(this);
        listView.setFadingEdgeLength(0);
        List<Map<String, String>> nameList = new ArrayList<Map<String, String>>();
        listCar = getUserCarList();
        for (int m = 0; m < listCar.size(); m++) {// initData为一个list类型的数据源
            Map<String, String> nameMap = new HashMap<String, String>();
            nameMap.put("name", listCar.get(m).getName().toString());
            nameList.add(nameMap);
        }
        SimpleAdapter adapter = new SimpleAdapter(mContext, nameList,
                R.layout.car_list, new String[] { "name" },
                new int[] { R.id.title });
        listView.setAdapter(adapter);
        linearLayoutMain.addView(listView);
        final AlertDialog dialog = new AlertDialog.Builder(this)
                .setTitle("我的爱车").setView(linearLayoutMain)
                // 在这里把写好的这个listview的布局加载dialog中
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        dialog.cancel();
                    }
                })
                .setNeutralButton("添加爱车",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                // TODO Auto-generated method stub
                                startActivity(new Intent(
                                        VehicleAllActivity.this,
                                        CarChooseActivity.class));
                                dialog.cancel();
                            }
                        }).create();
        dialog.show();
    
bubuko.com,布布扣

 

listView加载在Dialog里面,布布扣,bubuko.com

listView加载在Dialog里面

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/linximeng/p/3765518.html

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