Advertisement
Guest User

DialogFragment w/ Icons

a guest
Jul 24th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.98 KB | None | 0 0
  1. public class CategoryDialog extends DialogFragment {
  2.         ArrayList<Category> mSelectedItems;
  3.         MapActivity ma;
  4.  
  5.         public void setMapActivity(MapActivity m) {
  6.             ma = m;
  7.         }
  8.         @Override
  9.         public Dialog onCreateDialog(Bundle savedInstanceState) {
  10.             mSelectedItems = new ArrayList();  // Where we track the selected items
  11.             AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  12.  
  13.           // builder.setView((View) getLayoutInflater().inflate((R.layout.mapdialog_listview));
  14.             // Set the dialog title
  15.             builder.setTitle("Categories")
  16.                     .setMultiChoiceItems(R.array.category_array, null, // should be R.array.category_array
  17.                             new DialogInterface.OnMultiChoiceClickListener() {
  18.                                 Category[] cats = {Category.DINING, Category.SHOPPING, Category.SERVICE, Category.ATTRACTION, Category.HISTORY};
  19.  
  20.                                 @Override
  21.                                 public void onClick(DialogInterface dialog, int which,
  22.                                                     boolean isChecked) {
  23.                                     if (isChecked) {
  24.                                         // If the user checked the item, add it to the selected items
  25.                                         mSelectedItems.add(cats[which]);
  26.                                         //      visibleCategories.remove(cats[which]);
  27.                                     } else if (mSelectedItems.contains(which)) {
  28.                                         // Else, if the item is already in the array, remove it
  29.                                         mSelectedItems.remove(Integer.valueOf(which));
  30.                                     }
  31.                                 }
  32.                             })
  33.                             // Set the action buttons
  34.                     .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
  35.  
  36.                         private void saveVisibleCategories() {
  37.                         }
  38.  
  39.                         @Override
  40.                         public void onClick(DialogInterface dialog, int id) {
  41.                             visibleCategories = mSelectedItems;
  42.                             ma.updateMarkersByCategories();
  43.  
  44.  
  45.                             // User clicked OK, so save the mSelectedItems results somewhere
  46.                             // or return them to the component that opened the dialog
  47.                             // ...
  48.  
  49.                         }
  50.                     })
  51.                     .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  52.                         @Override
  53.                         public void onClick(DialogInterface dialog, int id) {
  54.                             dialog.dismiss();
  55.                             //...
  56.                         }
  57.                     });
  58.  
  59.             return builder.create();
  60.         }
  61.     }
  62.  
  63.  
  64. ####################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement