简单演示个弹出选择的弹框:
效果图:
1、布局layout就一个listview:
<ListView android:id="@+id/setting_recording_type_list" android:layout_width="match_parent" android:layout_height="wrap_content"></ListView>
2、实现代码:
private ListView motionDetection; private void setDeviveDialog(final int flag) { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(DeviceSettingActivity.this, R.style.HoloAlertDialog)); final AlertDialog dlg = builder.create(); dlg.setTitle(null); LayoutInflater inflater = dlg.getLayoutInflater(); View view = inflater.inflate(R.layout.setting_recording_type, null); dlg.setView(view); motionDetection = (ListView) view.findViewById(R.id.setting_recording_type_list); SimpleAdapter mAdapter = new SimpleAdapter(DeviceSettingActivity.this, getMenuData(flag), R.layout.resolution_list_item, new String[]{"title", "img"}, new int[]{R.id.title, R.id.img}); motionDetection.setAdapter(mAdapter); dlg.show(); motionDetection.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { dlg.dismiss(); } }); }
3、填充参数(这里flag可以指向不同item作不同画面):
private List<Map<String, Object>> getMenuData(int flag) { // map.put(参数名字,参数值) List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map = new HashMap<String, Object>(); map.put("title", "正常"); list.add(map); map = new HashMap<String, Object>(); map.put("title", "上下翻转"); // map.put("img", R.drawable.list_history_ico); list.add(map); map = new HashMap<String, Object>(); map.put("title", "垂直翻转"); // map.put("img", R.drawable.list_videophoto_ico); list.add(map); list.get(flag).put("img", R.drawable.btn_save_h); return list; }