Search in sources :

Example 1 with MultiSelectDialog

use of carbon.dialog.MultiSelectDialog in project Carbon by ZieIony.

the class SelectDialogActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    EditText titleText = findViewById(R.id.titleText);
    DropDown dropDown = findViewById(R.id.dropDown);
    dropDown.setItems(new String[] { "Single select", "Multi select" });
    StringFruitGenerator generator = new StringFruitGenerator();
    List<String> items = Stream.generate(generator::next).limit(5).toList();
    selectedItem = items.get(0);
    selectedItems = new ArrayList<>();
    selectedItems.add(selectedItem);
    findViewById(R.id.button).setOnClickListener(view -> {
        switch(dropDown.getSelectedIndex()) {
            case 0:
                {
                    SingleSelectDialog<String> dialog = new SingleSelectDialog<>(this);
                    if (titleText.length() > 0)
                        dialog.setTitle(titleText.getText());
                    dialog.setItems(items);
                    dialog.setOnDismissListener(dialogInterface -> selectedItem = dialog.getSelectedItem());
                    dialog.setSelectedItem(selectedItem);
                    dialog.show();
                }
                break;
            case 1:
                {
                    MultiSelectDialog<String> dialog = new MultiSelectDialog<>(this);
                    if (titleText.length() > 0)
                        dialog.setTitle(titleText.getText());
                    dialog.setItems(items);
                    dialog.addButton("ok", null);
                    dialog.setOnDismissListener(dialogInterface -> selectedItems = dialog.getSelectedItems());
                    dialog.setSelectedItems(selectedItems);
                    dialog.show();
                }
                break;
        }
    });
}
Also used : EditText(carbon.widget.EditText) ThemedActivity(tk.zielony.carbonsamples.ThemedActivity) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) MultiSelectDialog(carbon.dialog.MultiSelectDialog) SampleAnnotation(tk.zielony.carbonsamples.SampleAnnotation) EditText(carbon.widget.EditText) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(androidx.annotation.Nullable) SingleSelectDialog(carbon.dialog.SingleSelectDialog) R(tk.zielony.carbonsamples.R) DropDown(carbon.widget.DropDown) StringFruitGenerator(tk.zielony.randomdata.food.StringFruitGenerator) StringFruitGenerator(tk.zielony.randomdata.food.StringFruitGenerator) SingleSelectDialog(carbon.dialog.SingleSelectDialog) MultiSelectDialog(carbon.dialog.MultiSelectDialog) DropDown(carbon.widget.DropDown)

Aggregations

Bundle (android.os.Bundle)1 Nullable (androidx.annotation.Nullable)1 MultiSelectDialog (carbon.dialog.MultiSelectDialog)1 SingleSelectDialog (carbon.dialog.SingleSelectDialog)1 DropDown (carbon.widget.DropDown)1 EditText (carbon.widget.EditText)1 Stream (com.annimon.stream.Stream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 R (tk.zielony.carbonsamples.R)1 SampleAnnotation (tk.zielony.carbonsamples.SampleAnnotation)1 ThemedActivity (tk.zielony.carbonsamples.ThemedActivity)1 StringFruitGenerator (tk.zielony.randomdata.food.StringFruitGenerator)1