Example usage for android.widget ArrayAdapter add

List of usage examples for android.widget ArrayAdapter add

Introduction

In this page you can find the example usage for android.widget ArrayAdapter add.

Prototype

public void add(@Nullable T object) 

Source Link

Document

Adds the specified object at the end of the array.

Usage

From source file:com.glabs.homegenie.widgets.MediaServerDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    _view = getActivity().getLayoutInflater().inflate(R.layout.widget_control_mediaserver, null);
    builder.setView(_view);//  w  ww .j a  v a2  s  .  com

    builder.setMessage(_module.getDisplayName())
            .setPositiveButton("Play", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // Play to...
                    playMediaTo();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User cancelled the dialog
                }
            });

    mAdapter = new MediaFilesAdapter(_view.getContext(), R.layout.widget_control_mediaserver_item,
            new ArrayList<MediaEntry>());
    final ListView lv = (ListView) _view.findViewById(R.id.filesList);
    lv.setAdapter(mAdapter);
    //
    if (navigationStack.size() == 0) {
        navigationStack.add("0");
    }
    //
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            MediaEntry clicked = mAdapter.getItem(i);
            mAdapter.setSelectedIndex(i);
            _selectedMedia = null;
            //
            if (clicked.Class.indexOf("object.container") == 0) {
                // browse to folder
                _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
                if (clicked.Title.equals(PARENT_FOLDER)) {
                    navigationStack.removeLast();
                } else {
                    navigationStack.add(clicked.Id);
                }
                browseMediaFolder(lv);
            } else {
                // set current media file
                _selectedMedia = clicked;
                _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
            }
        }
    });
    //

    Control.getGroupModules("", new Control.GetGroupModulesCallback() {
        @Override
        public void groupModulesUpdated(ArrayList<Module> modules) {
            ArrayAdapter<CharSequence> playtoitems = new ArrayAdapter<CharSequence>(_view.getContext(),
                    android.R.layout.simple_spinner_item);
            //
            playtoitems.add("This device");
            //
            for (int m = 0; m < modules.size(); m++) {
                Module module = modules.get(m);
                ModuleParameter devtype = module.getParameter("UPnP.StandardDeviceType");
                if (devtype != null && devtype.Value.equals("MediaRenderer")) {
                    renderers.add(module);
                    playtoitems.add(Control.getUpnpDisplayName(module));
                }
            }
            //
            // Media Renderer Spinner Select
            Spinner playto = (Spinner) _view.findViewById(R.id.playto);
            playto.setAdapter(playtoitems);
            playto.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    _selectedMediaRender = null;
                    if (i > 0) {
                        _selectedMediaRender = renderers.get(i - 1);
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> adapterView) {

                }
            });

        }
    });
    //
    browseMediaFolder(lv);

    // Create the AlertDialog object and return it
    _dialog = builder.create();
    _dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            _dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
        }
    });
    return _dialog;
}

From source file:net.willwebberley.gowertides.ui.LocationDialog.java

private void initList() {
    ListView mListView = (ListView) layoutView.findViewById(R.id.location_list);
    ArrayAdapter<Object> ad = new ArrayAdapter<Object>(getActivity(), android.R.layout.simple_list_item_1);
    mListView.setAdapter(ad);/*w w w.  jav a2 s .  com*/

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            selected(i);
        }
    });

    ad.clear();
    for (int i = 0; i < names.length; i++) {
        ad.add(i + 1 + ": " + names[i]);
    }

    mListView.setAdapter(ad);
}

From source file:com.nextgis.maplibui.CreateRemoteTMSLayerDialog.java

@NonNull
@Override/* w  w  w .  ja va 2  s  .co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    LayoutInflater inflater = getActivity().getLayoutInflater();

    View view = inflater.inflate(R.layout.layout_create_tms, null);

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context,
            android.R.layout.simple_spinner_item);
    mSpinner = (Spinner) view.findViewById(R.id.layer_type);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinner.setAdapter(adapter);

    adapter.add(context.getString(R.string.tmstype_osm));
    adapter.add(context.getString(R.string.tmstype_normal));

    mInput = (EditText) view.findViewById(R.id.layer_name);
    mUrl = (EditText) view.findViewById(R.id.layer_url);

    mLogin = (EditText) view.findViewById(R.id.login);
    mPassword = (EditText) view.findViewById(R.id.password);

    if (null == savedInstanceState) {
        //mInput.setText(context.getResources().getText(R.string.osm));
        //mUrl.setText(context.getResources().getText(R.string.osm_url));
        //mSpinner.setSelection(0);
    } else {
        mInput.setText(savedInstanceState.getString(KEY_NAME));
        mUrl.setText(savedInstanceState.getString(KEY_URL));
        mLogin.setText(savedInstanceState.getString(KEY_LOGIN));
        mPassword.setText(savedInstanceState.getString(KEY_PASSWORD));
        mSpinner.setSelection(savedInstanceState.getInt(KEY_POSITION));
        mTitle = savedInstanceState.getString(KEY_TITLE);
        short id = savedInstanceState.getShort(KEY_ID);
        MapBase map = MapBase.getInstance();
        if (null != map) {
            ILayer iLayer = map.getLayerById(id);
            if (iLayer instanceof LayerGroup)
                mGroupLayer = (LayerGroup) iLayer;
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(mTitle).setIcon(R.drawable.ic_remote_tms).setView(view)
            .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (mSpinner.getSelectedItemPosition()) {
                    case 0:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 1:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }
                    String layerName = mInput.getText().toString();
                    String layerURL = mUrl.getText().toString();
                    String layerLogin = mLogin.getText().toString();
                    String layerPassword = mPassword.getText().toString();

                    //check if {x}, {y} or {z} present
                    if (!layerURL.contains("{x}") || !layerURL.contains("{y}") || !layerURL.contains("{z}")) {
                        Toast.makeText(context, R.string.error_invalid_url, Toast.LENGTH_SHORT).show();
                        return;
                    }

                    if (!layerURL.startsWith("http"))
                        layerURL = "http://" + layerURL;

                    //create new layer and store it and add it to the map
                    RemoteTMSLayerUI layer = new RemoteTMSLayerUI(mGroupLayer.getContext(),
                            mGroupLayer.cretateLayerStorage());
                    layer.setName(layerName);
                    layer.setURL(layerURL);
                    layer.setLogin(layerLogin);
                    layer.setPassword(layerPassword);
                    layer.setTMSType(tmsType);
                    layer.setVisible(true);

                    mGroupLayer.addLayer(layer);
                    mGroupLayer.save();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                }
            });
    // Create the AlertDialog object and return it
    return builder.create();
}

From source file:com.eugene.fithealthmaingit.MainActivity.java

private void widgetAdd() {
    AlertDialog.Builder builderSingle = new AlertDialog.Builder(MainActivity.this).setTitle("Choose Meal: ");
    final ArrayAdapter<String> mAdapterMoveMeal = new ArrayAdapter<>(MainActivity.this,
            android.R.layout.simple_list_item_1);
    mAdapterMoveMeal.add("Snack");
    mAdapterMoveMeal.add("Breakfast");
    mAdapterMoveMeal.add("Lunch");
    mAdapterMoveMeal.add("Dinner");
    builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
        @Override//from   w  w  w  .ja v  a2  s.c om
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builderSingle.setAdapter(mAdapterMoveMeal, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String strName = mAdapterMoveMeal.getItem(which);
            Intent i = new Intent(MainActivity.this, ChooseAddMealActivity.class);
            i.putExtra(Globals.MEAL_TYPE, strName);
            startActivity(i);
        }
    });
    builderSingle.show();
}

From source file:com.bluewatcher.activity.BlueWatcherActivity.java

private void initializeConfigurationOptions() {
    listView = (ListView) findViewById(R.id.list_config_view);

    ArrayAdapter<ConfigurationOption> adapter = new ArrayAdapter<ConfigurationOption>(this.getBaseContext(),
            android.R.layout.simple_list_item_1);
    adapter.add(
            new ConfigurationOption(NotificationsActivity.class, getString(R.string.notifications_service)));
    adapter.add(//  w  w w .  j  a v  a2s . c om
            new ConfigurationOption(ControlModesActivity.class, getString(R.string.phone_control_menu_text)));
    adapter.add(new ConfigurationOption(PhoneFinderConfigActivity.class,
            getString(R.string.phone_finder_service), servicesContainer));
    adapter.add(new ConfigurationOption(TimeConfigActivity.class, getString(R.string.time_sync_service)));
    adapter.add(new ConfigurationOption(AvailableServicesActivity.class,
            getString(R.string.show_available_services_text), servicesContainer));
    adapter.add(new ConfigurationOption(SettingsActivity.class, getString(R.string.bluewatcher_settings)));
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new OnConfigurationOptionSelected(this, listView));
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java

private void InitiateClick() {
    listContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from   w  w  w . j  a  va2s . c  o m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mealId1 = mItem.get(position - 1).getID();
            mealBrand = mItem.get(position - 1).getBrand();
            mealFaborite = "false";
            AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity())
                    .setTitle("Choose Meal: ");
            final ArrayAdapter<String> mAdapterMoveMeal = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_list_item_1);
            mAdapterMoveMeal.add("Snack");
            mAdapterMoveMeal.add("Breakfast");
            mAdapterMoveMeal.add("Lunch");
            mAdapterMoveMeal.add("Dinner");
            builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builderSingle.setAdapter(mAdapterMoveMeal, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String strName = mAdapterMoveMeal.getItem(which);
                    Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class);
                    i.putExtra(Globals.MEAL_TYPE, strName);
                    i.putExtra(Globals.MEAL_FAVORITE, "false");
                    i.putExtra(Globals.MEAL_ID, mealId1);
                    i.putExtra(Globals.MEAL_BRAND, mealBrand);
                    startActivity(i);
                }
            });
            builderSingle.show();
        }
    });
}

From source file:com.liferay.alerts.activity.CommentsActivity.java

private void _registerBroadcastReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_ADD_COMMENT);
    filter.addAction(ACTION_UPDATE_COMMENTS_LIST);

    _receiver = new BroadcastReceiver() {

        @Override//w w w .  j  a v a2  s  . c o  m
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            ListView listView = (ListView) findViewById(R.id.comments);

            if (ACTION_UPDATE_COMMENTS_LIST.equals(action)) {
                ArrayList<Alert> alerts = intent.getParcelableArrayListExtra(EXTRA_ALERTS);

                ArrayAdapter<Alert> adapter = new CommentListAdapter(getApplicationContext(), alerts);

                listView.setAdapter(adapter);
            } else if (ACTION_ADD_COMMENT.equals(action)) {
                Alert alert = intent.getParcelableExtra(EXTRA_ALERT);

                ArrayAdapter<Alert> adapter = (ArrayAdapter<Alert>) listView.getAdapter();

                adapter.add(alert);
            }
        }

    };

    _getBroadcastManager().registerReceiver(_receiver, filter);
}

From source file:org.akvo.flow.activity.GeoshapeActivity.java

private void displayProperties() {
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line);
    for (Feature.Property property : mCurrentFeature.getProperties()) {
        adapter.add(String.format("%s: %s", property.mDisplayName, property.mDisplayValue));
    }//ww  w.ja  v a  2s .  co  m

    new AlertDialog.Builder(GeoshapeActivity.this).setTitle("Properties").setAdapter(adapter, null).show();
}

From source file:net.jongrakko.zipsuri.activity.RegisterExpertActivity.java

private void setDistance(final AddressModel addressModel) {
    ArrayAdapter<String> mAdapter = new ArrayAdapter<>(getContext(), R.layout.adapter_single_choice_list);
    final int[] distances = { 5, 10, 30, 50 };
    for (int distance : distances) {
        mAdapter.add(distance + "Km");
    }/*from ww  w  .  jav a 2s.  co m*/
    new AlertDialog.Builder(getContext()).setTitle("? ?.").setCancelable(false)
            .setSingleChoiceItems(mAdapter, 0, null)
            .setPositiveButton("?", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
                    addressModel.setDistance(distances[selectedPosition]);
                    setAddressModel(addressModel);
                }
            }).show();
}

From source file:com.silentcircle.contacts.activities.ActionBarAdapter.java

private void setupNavigationList() {
    ArrayAdapter<String> navAdapter = new CustomArrayAdapter(mContext, R.layout.people_navigation_item);
    navAdapter.add(mContext.getString(R.string.contactsAllLabel));
    navAdapter.add(mContext.getString(R.string.contactsFavoritesLabel));
    navAdapter.add(mContext.getString(R.string.contactsGroupsLabel));
    navAdapter.add(mContext.getString(R.string.recentCallsIconLabel));
    mActionBar.setListNavigationCallbacks(navAdapter, mNavigationListener);
}