@NonNull @SuppressLint("InflateParams") @Override public Dialog onCreateDialog(Bundle savedInstanceState) { FragmentActivity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.solarsystem, null); builder.setView(view); builder.setPositiveButton("Set", new MarketFetchClickListener()); builder.setNegativeButton("Cancel", null); Spinner sp_region = (Spinner) view.findViewById(R.id.sp_solarsystem_region); sp_system = (Spinner) view.findViewById(R.id.sp_solarsystem_system); system = 30000142; regions = Starmap.getRegions(); ArrayList<CharSequence> region_list = new ArrayList<>(); for (SolarSystemRegion r : regions) { region_list.add(r.Name); } ArrayAdapter<CharSequence> region_adapter = new ArrayAdapter<>(activity, android.R.layout.simple_spinner_item, region_list); region_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); SolarSystemRegion reg = Starmap.getRegion(Starmap.getSolarSystem(system).Region); sp_region.setAdapter(region_adapter); sp_region.setSelection(regions.indexOf(reg), true); setRegionSystems(reg); sp_region.setOnItemSelectedListener(new RegionSelectedListener()); sp_system.setOnItemSelectedListener(new SystemSelectedListener()); return builder.create(); }
private void setRegionSystems(SolarSystemRegion r) { Activity act = getActivity(); systems = Starmap.getSolarSystems(r.ID); ArrayList<CharSequence> systems_list = new ArrayList<>(); for (SolarSystem s : systems) { systems_list.add(s.Name); } ArrayAdapter<CharSequence> systems_adapter = new ArrayAdapter<>(act, android.R.layout.simple_spinner_item, systems_list); systems_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_system.setAdapter(systems_adapter); int index = systems.indexOf(Starmap.getSolarSystem(system)); if (index == -1) { system = systems.get(0).ID; sp_system.setSelection(0, true); } else { sp_system.setSelection(index, true); } }
private void updateSystem(Spinner spinner, int system) { RecentSystemsDA.putSystem(system); system_ids = new ArrayList<>(); List<String> system_names = new ArrayList<>(); for (int id : RecentSystemsDA.getSystems()) { system_ids.add(id); system_names.add(Starmap.getSolarSystem(id).Name); } system_ids.add(-1); system_names.add("[ Other ... ]"); ArrayAdapter<String> sys_spinner_adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, system_names); sys_spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(sys_spinner_adapter); spinner.setSelection(system_ids.indexOf(system)); }