// 两列选择框 private void dialogRoommate2( final String title, final String key1, final String key2, final TextView textView, List<Dialog_forlist> list) { final List<String> list_name = new ArrayList<>(); final Map<String, List<String>> map_city = new HashMap<>(); final Map<String, List<Integer>> map_id = new HashMap<>(); for (Dialog_forlist ll : list) { list_name.add(ll.getName()); map_city.put(ll.getName(), ll.getList()); map_id.put(ll.getName(), ll.getList_id()); } AlertDialog.Builder builder = new AlertDialog.Builder(ReleaseActivity.this); View view = View.inflate(ReleaseActivity.this, R.layout.dialog_addroommate2, null); TextView textView_title = (TextView) view.findViewById(R.id.dialog_title); textView_title.setText(title); final ListView listView = (ListView) view.findViewById(R.id.dialog_listview); final ListView listView2 = (ListView) view.findViewById(R.id.dialog_listview2); builder.setView(view); final Dialog dialog = builder.show(); listView.setAdapter( new ArrayAdapter(ReleaseActivity.this, R.layout.dialog_listview_layout, list_name)); list_city = map_city.get(list_name.get(0)); listView2.setAdapter( new ArrayAdapter(ReleaseActivity.this, R.layout.dialog_listview_layout, list_city)); listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { map_release.put(key1, list_name.get(position)); // 根据第一个ListView中item的值来确定ListView2的数据 list_city = map_city.get(list_name.get(position)); // 城市名字的list list_id = map_id.get(list_name.get(position)); listView2.setAdapter( new ArrayAdapter(ReleaseActivity.this, R.layout.dialog_listview_layout, list_city)); listView2.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if ("区域".equals(title)) { String string = map_release.get(key1) + "-" + list_city.get(position); textView.setText(string); map_release.put(key2, list_city.get(position).toString()); } else if ("籍贯".equals(title)) { String string = map_release.get(key1) + "-" + list_city.get(position); textView.setText(string); map_release.put(key2, list_id.get(position).toString()); } else { String string = list_city.get(position); textView.setText(string); map_release.put(key2, list_id.get(position).toString()); } dialog.dismiss(); } }); } }); }