Search in sources :

Example 1 with DropDown

use of carbon.widget.DropDown 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)

Example 2 with DropDown

use of carbon.widget.DropDown in project Carbon by ZieIony.

the class DropDownActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    String[] days = new String[31];
    for (int i = 0; i < days.length; i++) days[i] = "" + (i + 1);
    DropDown day = findViewById(R.id.day);
    day.setItems(days);
    DropDown month = findViewById(R.id.month);
    month.setItems(months);
    String[] years = new String[30];
    for (int i = 0; i < years.length; i++) years[i] = "" + (i + 1987);
    DropDown year = findViewById(R.id.year);
    year.setItems(years);
}
Also used : DropDown(carbon.widget.DropDown)

Aggregations

DropDown (carbon.widget.DropDown)2 Bundle (android.os.Bundle)1 Nullable (androidx.annotation.Nullable)1 MultiSelectDialog (carbon.dialog.MultiSelectDialog)1 SingleSelectDialog (carbon.dialog.SingleSelectDialog)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