Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CategoryDialog extends DialogFragment {
- ArrayList<Category> mSelectedItems;
- MapActivity ma;
- public void setMapActivity(MapActivity m) {
- ma = m;
- }
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- mSelectedItems = new ArrayList(); // Where we track the selected items
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- // builder.setView((View) getLayoutInflater().inflate((R.layout.mapdialog_listview));
- // Set the dialog title
- builder.setTitle("Categories")
- .setMultiChoiceItems(R.array.category_array, null, // should be R.array.category_array
- new DialogInterface.OnMultiChoiceClickListener() {
- Category[] cats = {Category.DINING, Category.SHOPPING, Category.SERVICE, Category.ATTRACTION, Category.HISTORY};
- @Override
- public void onClick(DialogInterface dialog, int which,
- boolean isChecked) {
- if (isChecked) {
- // If the user checked the item, add it to the selected items
- mSelectedItems.add(cats[which]);
- // visibleCategories.remove(cats[which]);
- } else if (mSelectedItems.contains(which)) {
- // Else, if the item is already in the array, remove it
- mSelectedItems.remove(Integer.valueOf(which));
- }
- }
- })
- // Set the action buttons
- .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
- private void saveVisibleCategories() {
- }
- @Override
- public void onClick(DialogInterface dialog, int id) {
- visibleCategories = mSelectedItems;
- ma.updateMarkersByCategories();
- // User clicked OK, so save the mSelectedItems results somewhere
- // or return them to the component that opened the dialog
- // ...
- }
- })
- .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int id) {
- dialog.dismiss();
- //...
- }
- });
- return builder.create();
- }
- }
- ####################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement