List of usage examples for android.widget ArrayAdapter insert
public void insert(@Nullable T object, int index)
From source file:com.example.flashcards.wizardpager.wizard.ui.TopicChoiceFragment.java
private void createNewTopic(String value) { // make changes on page if (value.trim() != "") { Log.d(LOG_TAG, "Name: " + value); SingleTopicChoicePage fixedChoicePage = (SingleTopicChoicePage) mPage; Topic topic = new Topic(value); fixedChoicePage.addTopic(topic); ArrayAdapter<Object> adapter = (ArrayAdapter) getListAdapter(); adapter.insert(topic.getName(), adapter.getCount() - 1); // continue like normally mPage.getData().putSerializable(SingleTopicChoicePage.TOPIC, topic); mPage.notifyDataChanged();/* w w w . j a va 2 s.c o m*/ } }
From source file:org.videolan.vlc.gui.dialogs.AdvOptionsDialog.java
private void initChapterSpinner() { final MediaPlayer mediaplayer = VLCInstance.getMainMediaPlayer(); int chaptersCount = mediaplayer.getChapterCount(); if (chaptersCount <= 1) { mChapters.setVisibility(View.GONE); mChaptersTitle.setVisibility(View.GONE); return;/*ww w . j av a 2 s . c o m*/ } ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item); String chapterDescription; for (int i = 0; i < chaptersCount; ++i) { chapterDescription = mediaplayer.getChapterDescription(i); adapter.insert(chapterDescription != null ? chapterDescription : Integer.toString(i), i); } adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mChapters.setAdapter(adapter); mChapters.setSelection(mediaplayer.getChapter()); mChapters.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != mediaplayer.getChapter()) mediaplayer.setChapter(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.spatialnetworks.fulcrum.widget.DynamicListView.java
private void swapElements(int indexOne, int indexTwo) { ListAdapter listAdapter = getAdapter(); if (listAdapter instanceof WrapperListAdapter) { WrapperListAdapter wrapperListAdapter = (WrapperListAdapter) listAdapter; listAdapter = wrapperListAdapter.getWrappedAdapter(); }/*from w ww .ja v a 2 s. c o m*/ if (!(listAdapter instanceof ArrayAdapter)) { throw new RuntimeException("DynamicListView can only swap elements using an ArrayAdapter"); } else { ArrayAdapter arrayAdapter = (ArrayAdapter) listAdapter; Object obj2 = arrayAdapter.getItem(indexTwo); //noinspection unchecked arrayAdapter.remove(obj2); //noinspection unchecked arrayAdapter.insert(obj2, indexOne); } }