Java Code Examples for android.widget.ArrayAdapter#add()

The following examples show how to use android.widget.ArrayAdapter#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalAdapter.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private void createContextualMenu(final int pos){
    LocalGallery gallery=(LocalGallery) filter.get(pos);
    ArrayAdapter<String>adapter=new ArrayAdapter<>(context,android.R.layout.select_dialog_item);
    adapter.add(context.getString(R.string.delete_gallery_size_format,sizeForGallery(gallery)));
    adapter.add(context.getString(R.string.create_zip));
    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.KITKAT)adapter.add(context.getString(R.string.create_pdf));//api 19
    MaterialAlertDialogBuilder builder=new MaterialAlertDialogBuilder(context);
    builder.setTitle(R.string.settings).setIcon(R.drawable.ic_settings);
    builder.setAdapter(adapter, (dialog, which) -> {
        switch (which){
            case 0:showDialogDelete(pos);break;
            case 1:createZIP(pos);break;
            case 2:showDialogPDF(pos);break;
        }
    }).show();
}
 
Example 2
Source File: SwitchStyleActivity.java    From android with Apache License 2.0 6 votes vote down vote up
private void updateColorSpinner() {
  ArrayAdapter<ThemeColor> adapter =
      new ArrayAdapter(this, R.layout.gray_spinner_item);
  adapter.setDropDownViewResource(R.layout.gray_spinner_dropdown_item);
  int pos = 0;
  if (currentStyle != null && currentStyle.getColors() != null) {
    int i = 0;
    for (ThemeColor color : currentStyle.getColors()) {
      adapter.add(color);
      if (color == currentStyle.getDefaultColor()) {
        pos = i;
      }
      i++;
    }
  }
  colorSpinner.setAdapter(adapter);
  colorSpinner.setSelection(pos);
}
 
Example 3
Source File: AbstractModelManager.java    From fingen with Apache License 2.0 6 votes vote down vote up
private static ArrayAdapter<String> createTreeArrayAdapter(Activity activity, List<BaseNode> nodes) {
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, android.R.layout.simple_list_item_1);
    for (BaseNode node : nodes) {
        String prefix = "";
        for (int i = 0; i < node.getLevel() - 2; i++) {
            prefix = prefix + "\t\t";
        }
        if (!prefix.isEmpty()) {
            if (node.isLastChildren()) {
                prefix = prefix + "└ ";
            } else {
                prefix = prefix + "├ ";
            }
        }
        arrayAdapter.add(prefix + node.getModel().getName());
    }
    return arrayAdapter;
}
 
Example 4
Source File: MainActivity.java    From ArcLayout with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ListView listView = (ListView) findViewById(R.id.list);
  listView.setOnItemClickListener(this);

  ArrayAdapter<String> demoAdapter = new ArrayAdapter<String>(this,
      android.R.layout.simple_list_item_1);

  for (Demo demo : Demo.values()) {
    demoAdapter.add(getString(demo.titleResId));
  }

  listView.setAdapter(demoAdapter);
}
 
Example 5
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void layoutOverflowPanelItems(List<MenuItem> menuItems) {
    ArrayAdapter<MenuItem> overflowPanelAdapter = (ArrayAdapter<MenuItem>) mOverflowPanel.getAdapter();
    overflowPanelAdapter.clear();
    final int size = menuItems.size();
    for (int i = 0; i < size; i++) {
        overflowPanelAdapter.add(menuItems.get(i));
    }
    mOverflowPanel.setAdapter(overflowPanelAdapter);
    if (mOpenOverflowUpwards) {
        mOverflowPanel.setY(0);
    } else {
        mOverflowPanel.setY(mOverflowButtonSize.getHeight());
    }
    int width = Math.max(getOverflowWidth(), mOverflowButtonSize.getWidth());
    int height = calculateOverflowHeight(MAX_OVERFLOW_SIZE);
    mOverflowPanelSize = new Size(width, height);
    setSize(mOverflowPanel, mOverflowPanelSize);
}
 
Example 6
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
/**
 * Set the list of words to display for guessing.
 */
private void resetWords(List<String> words) {
    ListView list = (ListView) findViewById(R.id.listView);

    ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
            android.R.layout.simple_list_item_1);

    for (String st : words) {
        adapter.add(st);
    }

    list.setAdapter(adapter);
}
 
Example 7
Source File: ConfigureStandupTimer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initializeTeamNamesSpinner() {
    Spinner s = (Spinner) findViewById(R.id.team_names);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, Team.findAllTeamNames(this));
    adapter.add(" [No Team] ");
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s.setAdapter(adapter);
    s.setSelection(teamNamesPos);
}
 
Example 8
Source File: LogActivity.java    From Outlook-SDK-Android with MIT License 5 votes vote down vote up
private void refreshTestGroupsAndLog() {

        ArrayAdapter<String> adapter = (ArrayAdapter<String>) mTestLogSpinner.getAdapter();
        adapter.clear();
        adapter.add("All");
        adapter.add("Only failed");
        mTestLogSpinner.setSelection(0);
        selectLogResults(0);
    }
 
Example 9
Source File: AutoCompleteListViewTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void setAdapter_shouldShowEmptyViewWhenItemIsRemovedFromAdapter() throws Exception {
    ArrayAdapter adapter = new ArrayAdapter(ACTIVITY, 0);
    adapter.add(new Object());
    View empty = new View(ACTIVITY);
    autoCompleteListView.setEmptyView(empty);
    autoCompleteListView.setAdapter(adapter);
    autoCompleteListView.setVisibility(View.VISIBLE);
    adapter.clear();
    assertThat(empty).isVisible();
}
 
Example 10
Source File: Adapters.java    From Android-Commons with Apache License 2.0 5 votes vote down vote up
/**
    * Adds all the items from the specified collection to the given adapter at once
    *
    * @param adapter the adapter to insert the items into
    * @param items the items to insert
    */
@SuppressLint("NewApi")
public static <T> void addAll(final ArrayAdapter<T> adapter, final Collection<T> items) {
   	if (Build.VERSION.SDK_INT >= 11) {
       	adapter.addAll(items);
   	}
   	else {
   		for (T item : items) {
   			adapter.add(item);
   		}
   	}
   }
 
Example 11
Source File: ChannelDetailActivity.java    From buddycloud-android with Apache License 2.0 5 votes vote down vote up
private void setSpinnerText(Spinner spinner, 
		List<String> values,
		Integer[] valueDetails,
		String selectedValue) {
	ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
			this, R.layout.spinner_item_layout);
	
	for (int pos=0; pos < valueDetails.length; pos++) {
		adapter.add(getString(valueDetails[pos]));
	}
	adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	spinner.setAdapter(adapter);
	spinner.setSelection(values.indexOf(selectedValue));
}
 
Example 12
Source File: ConfigureStandupTimer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initializeTeamNamesSpinner() {
    Spinner s = (Spinner) findViewById(R.id.team_names);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, Team.findAllTeamNames(this));
    adapter.add(" [No Team] ");
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    s.setAdapter(adapter);
    s.setSelection(teamNamesPos);
}
 
Example 13
Source File: MainActivity.java    From Outlook-SDK-Android with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
   private void refreshTestGroupsAndLog() {
       mLog = new StringBuilder();

       Map<String, Map<String, String>> exclusions = GetExclusions(getResources().openRawResource(R.raw.excluded_tests));

       ArrayAdapter<TestGroup> adapter = (ArrayAdapter<TestGroup>) mTestGroupSpinner.getAdapter();
       adapter.clear();

       adapter.add(new ExchangeTests());

	mTestGroupSpinner.setSelection(0);
	selectTestGroup(0);
}
 
Example 14
Source File: SampleActivity.java    From SnackbarBuilder with Apache License 2.0 5 votes vote down vote up
private ListAdapter createAdapter() {
  final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
  listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      String item = adapter.getItem(position);
      samples.get(item).onClick(view);
    }
  });
  for (String sample : samples.keySet()) {
    adapter.add(sample);
  }
  return adapter;
}
 
Example 15
Source File: WeatherActivity.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
private void showPreview() {
    final ArrayAdapter<String> arrayAdapter
            = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1);
    arrayAdapter.add("晴");
    arrayAdapter.add("多云");
    arrayAdapter.add("阴");
    arrayAdapter.add("雾");
    arrayAdapter.add("雨");
    arrayAdapter.add("雨夹雪");
    arrayAdapter.add("雪");
    arrayAdapter.add("霾");

    ListView listView = new ListView(this);
    listView.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    listView.setDividerHeight(1);
    listView.setAdapter(arrayAdapter);

    final MaterialDialog alert = new MaterialDialog(this).setContentView(listView);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mSkyView.setWeather(parent.getAdapter().getItem(position).toString());
            alert.dismiss();
        }
    });
    alert.setCanceledOnTouchOutside(true);
    alert.show();
}
 
Example 16
Source File: KeyAssignmentUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the arrayadapter to reflect changes in the list of keys assigned.
 *
 * @param keyListAdapter The ArrayAdapter to be updated
 * @param keyCombos The present set of assigned keys
 * @param context The context of the activity the call came from
 */
public static void updateKeyListAdapter(
    ArrayAdapter<CharSequence> keyListAdapter, Set<Long> keyCombos, Context context) {
  keyListAdapter.clear();
  for (long keyCombo : keyCombos) {
    keyListAdapter.add(KeyAssignmentUtils.describeExtendedKeyCode(keyCombo, context));
  }

  /* Sort the list so the keys appear in a consistent place */
  keyListAdapter.sort(
      (charSequence0, charSequence1) ->
          charSequence0.toString().compareToIgnoreCase(charSequence1.toString()));
}
 
Example 17
Source File: ImageTransferFormatSelectorPageFragment.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Context context = getContext();
    if (context == null) return;

    Size[] resolutions = mIsEInkMode ? kEInkResolutions : kStandardResolutions;

    // add a radio button list
    int checkedItem = -1;
    final ArrayAdapter<String> resolutionsAdapter = new ArrayAdapter<>(context, android.R.layout.select_dialog_singlechoice);
    for (int i = 0; i < resolutions.length; i++) {
        Size size = resolutions[i];
        resolutionsAdapter.add(String.format(Locale.US, "%d x %d", size.getWidth(), size.getHeight()));

        if (size.equals(mResolution)) {
            checkedItem = i;
        }
    }

    ListView listView = view.findViewById(R.id.listView);
    listView.setAdapter(resolutionsAdapter);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    if (checkedItem >= 0) {
        listView.setItemChecked(checkedItem, true);
    }

    listView.setOnItemClickListener((parent, view1, position, id) -> {
        if (mListener != null) {
            Size[] currentResolutions = mIsEInkMode ? kEInkResolutions : kStandardResolutions;
            mListener.onResolutionSelected(currentResolutions[position], mIsEInkMode);
        }
    });

}
 
Example 18
Source File: ColumnDialog.java    From Onosendai with Apache License 2.0 4 votes vote down vote up
private void setDurationSpinner (final int mins, final ArrayAdapter<Duration> refAdapter) {
	final Duration duration = new Duration(mins > 0 ? mins : 0);
	final int pos = refAdapter.getPosition(duration);
	if (pos < 0) refAdapter.add(duration); // Allow for any value to have been chosen before.
	this.spnRefresh.setSelection(pos < 0 ? refAdapter.getPosition(duration) : pos);
}
 
Example 19
Source File: GeocodeActivity.java    From PocketMaps with MIT License 4 votes vote down vote up
private void showSearchEngine()
{
  setContentView(R.layout.activity_geocode);
  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
  adapter.add(ENGINE_OSM);
  adapter.add(ENGINE_GOOGLE);
  adapter.add(ENGINE_OFFLINE);
  geoSpinner = (Spinner) findViewById(R.id.geoSpinner);
  geoSpinner.setAdapter(adapter);
  geoSpinner.setSelection(Variable.getVariable().getGeocodeSearchEngine());
  geoSpinner.setOnItemSelectedListener(createOnSearchEngineChanged());
  okButton = (Button) findViewById(R.id.geoOk);
  txtLocation = (AutoCompleteTextView) findViewById(R.id.geoLocation);
  cb_multi_match_only = (CheckBox) findViewById(R.id.checkbox_multi_match_only);
  cb_explicit_search_text = (CheckBox) findViewById(R.id.checkbox_explicit_search_text);
  cb_city_nodes = (CheckBox) findViewById(R.id.checkbox_city_nodes);
  cb_street_nodes = (CheckBox) findViewById(R.id.checkbox_street_nodes);
  cb_lineA = findViewById(R.id.lineA);
  cb_lineB = findViewById(R.id.lineB);
  if ((Variable.getVariable().getOfflineSearchBits() & GeocoderLocal.BIT_MULT) > 0)
  {
    cb_multi_match_only.setChecked(true);
    onCheckboxClicked(cb_multi_match_only);
  }
  if ((Variable.getVariable().getOfflineSearchBits() & GeocoderLocal.BIT_EXPL) > 0)
  {
    cb_explicit_search_text.setChecked(true);
  }
  if ((Variable.getVariable().getOfflineSearchBits() & GeocoderLocal.BIT_CITY) > 0)
  {
    cb_city_nodes.setChecked(true);
  }
  if ((Variable.getVariable().getOfflineSearchBits() & GeocoderLocal.BIT_STREET) > 0)
  {
    cb_street_nodes.setChecked(true);
  }
  String preText = ShowLocationActivity.locationSearchString;
  if (preText != null)
  {
    txtLocation.setText(preText);
    ShowLocationActivity.locationSearchString = null;
  }
  ArrayAdapter<String> autoAdapter = new ArrayAdapter<String>(this,
      android.R.layout.simple_list_item_1,
      Variable.getVariable().getGeocodeSearchTextList());
  txtLocation.setAdapter(autoAdapter);

  okButton.setOnClickListener(this);
}
 
Example 20
Source File: VideoPlayActivity.java    From dtube-mobile-unofficial with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        Log.d("dtube","Key event "+event.getKeyCode()+"VS"+KeyEvent.KEYCODE_MEDIA_REWIND);
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_ENTER:
            case KeyEvent.KEYCODE_DPAD_CENTER:
                if (getCurrentFocus() != null && getCurrentFocus() instanceof  ViewGroup) {
                    //Open a dialog for options on a comment
                    if (getCurrentFocus().getId() == R.id.comments_lv) {

                        final View commentView = commentsListView.getSelectedView();
                        final AlertDialog.Builder builderSingle = new AlertDialog.Builder(VideoPlayActivity.this);

                        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(VideoPlayActivity.this, android.R.layout.select_dialog_item);
                        arrayAdapter.add(getResources().getString(R.string.like_comment));
                        arrayAdapter.add(getResources().getString(R.string.dislike_comment));

                        builderSingle.setNegativeButton("cancel", null);

                        builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
                            switch (which) {
                                case 0:
                                commentView.findViewById(R.id.comment_like).performClick();
                                break;

                                case 1:
                                    commentView.findViewById(R.id.comment_dislike).performClick();
                                    break;

                                case 2:
                                    commentView.findViewById(R.id.comment_reply).performClick();
                                    break;
                            }
                        });

                        //dialog display is delayed to prevent misfocus
                        commentView.postDelayed(builderSingle::show,10);

                        Log.d("dtube", "dispatch" + ((ViewGroup) getCurrentFocus()).getChildAt(0).getId() + "VS" + R.id.comment_item);
                    }else if (getCurrentFocus().getId() == R.id.suggestions_lv) {
                        //select the suggested video
                        onItemClick(suggestedVideosListView.getSelectedItemPosition());
                    }
                }
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                wakeMediaControls();
                MediaPlayerSingleton.getInstance(this).togglePlayPause();
                break;

            case KeyEvent.KEYCODE_MEDIA_REWIND:
            case KeyEvent.KEYCODE_MEDIA_STEP_BACKWARD:
            case KeyEvent.KEYCODE_MEDIA_SKIP_BACKWARD:
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                wakeMediaControls();
                MediaPlayerSingleton.getInstance(this).rewind();
                break;

            case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
            case KeyEvent.KEYCODE_MEDIA_SKIP_FORWARD:
            case KeyEvent.KEYCODE_MEDIA_STEP_FORWARD:
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                wakeMediaControls();
                MediaPlayerSingleton.getInstance(this).fastForward();
                break;

        }
    }
    return super.dispatchKeyEvent(event);
}