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:org.retroshare.android.ConversationInfoDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    getDialog().setTitle("Conversation Details");

    RsConversationService.ConversationInfo conversationInfo = getArguments()
            .getParcelable(CONVERSATION_INFO_EXTRA);

    View a = inflater.inflate(R.layout.conversation_info_fragment_layout, container);

    TextView privacyTextView = (TextView) a.findViewById(R.id.conversation_info_privacy);
    if (conversationInfo.isPrivate())
        privacyTextView.setText(R.string._private);
    else/*w  w  w.ja v  a  2 s .  co  m*/
        privacyTextView.setText(R.string._public);

    if (conversationInfo.hasTitle()) {
        a.findViewById(R.id.conversation_info_title_layout).setVisibility(View.VISIBLE);
        ((TextView) a.findViewById(R.id.conversation_info_title)).setText(conversationInfo.getTitle());
    } else
        a.findViewById(R.id.conversation_info_title_layout).setVisibility(View.GONE);

    if (conversationInfo.hasTopic()) {
        a.findViewById(R.id.conversation_info_topic_layout).setVisibility(View.VISIBLE);
        ((TextView) a.findViewById(R.id.conversation_info_topic)).setText(conversationInfo.getTopic());
    } else
        a.findViewById(R.id.conversation_info_topic_layout).setVisibility(View.GONE);

    if (conversationInfo.getParticipantsCount() > 0) {
        a.findViewById(R.id.conversation_info_participants_layout).setVisibility(View.VISIBLE);
        ArrayAdapter adapter = new ArrayAdapter(mContext, R.layout.participants_list_item,
                R.id.participant_name_text_view);
        ((ListView) a.findViewById(R.id.conversation_info_participants)).setAdapter(adapter);
        for (CharSequence nick : conversationInfo.getParticipantsNick())
            adapter.add(nick);
    } else
        a.findViewById(R.id.conversation_info_participants_layout).setVisibility(View.GONE);

    return a;
}

From source file:org.mozilla.gecko.AutoCompletePopup.java

public void show(JSONArray suggestions, JSONArray rect, double zoom) {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.autocomplete_list_item);
    for (int i = 0; i < suggestions.length(); i++) {
        try {/*from  ww  w. j  ava  2s . c o  m*/
            adapter.add(suggestions.get(i).toString());
        } catch (JSONException e) {
            Log.i(LOGTAG, "JSONException: " + e);
        }
    }

    setAdapter(adapter);

    if (!isShown()) {
        setVisibility(View.VISIBLE);
        startAnimation(mAnimation);
    }

    if (mLayout == null) {
        mLayout = (RelativeLayout.LayoutParams) getLayoutParams();
        mWidth = mLayout.width;
        mHeight = mLayout.height;
    }

    int left = 0;
    int top = 0;
    int width = 0;
    int height = 0;

    try {
        left = (int) (rect.getDouble(0) * zoom);
        top = (int) (rect.getDouble(1) * zoom);
        width = (int) (rect.getDouble(2) * zoom);
        height = (int) (rect.getDouble(3) * zoom);
    } catch (JSONException e) {
    }

    int listWidth = mWidth;
    int listHeight = mHeight;
    int listLeft = left < 0 ? 0 : left;
    int listTop = top + height;

    FloatSize viewport = GeckoApp.mAppContext.getLayerController().getViewportSize();

    // Late initializing variable to allow DisplayMetrics not to be null and avoid NPE
    if (sMinWidth == 0) {
        DisplayMetrics metrics = new DisplayMetrics();
        GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        sMinWidth = (int) (AUTOCOMPLETE_MIN_WIDTH_IN_DPI * metrics.density);
        sRowHeight = (int) (AUTOCOMPLETE_ROW_HEIGHT_IN_DPI * metrics.density);
    }

    // If the textbox is smaller than the screen-width,
    // shrink the list's width
    if ((left + width) < viewport.width)
        listWidth = left < 0 ? left + width : width;

    // listWidth can be negative if it is a constant - FILL_PARENT or MATCH_PARENT
    if (listWidth >= 0 && listWidth < sMinWidth) {
        listWidth = sMinWidth;

        if ((listLeft + listWidth) > viewport.width)
            listLeft = (int) (viewport.width - listWidth);
    }

    listHeight = sRowHeight * adapter.getCount();

    // The text box doesnt fit below
    if ((listTop + listHeight) > viewport.height) {
        // Find where the maximum space is, and fit it there
        if ((viewport.height - listTop) > top) {
            // Shrink the height to fit it below the text-box
            listHeight = (int) (viewport.height - listTop);
        } else {
            if (listHeight < top) {
                // No shrinking needed to fit on top
                listTop = (top - listHeight);
            } else {
                // Shrink to available space on top
                listTop = 0;
                listHeight = top;
            }
        }
    }

    mLayout = new RelativeLayout.LayoutParams(listWidth, listHeight);
    mLayout.setMargins(listLeft, listTop, 0, 0);
    setLayoutParams(mLayout);
    requestLayout();
}

From source file:com.microsoft.windowsazure.messaging.e2etestapp.MainActivity.java

@SuppressWarnings("unchecked")
private void refreshTestGroupsAndLog() {
    mLog = new StringBuilder();

    ArrayAdapter<TestGroup> adapter = (ArrayAdapter<TestGroup>) mTestGroupSpinner.getAdapter();
    adapter.clear();//from w  w  w .j  a  va2s.  c  o  m
    adapter.add(new MiscTests());
    mTestGroupSpinner.setSelection(0);
    selectTestGroup(0);
}

From source file:com.app4am.app4am.LatestNewsListFragment.java

/**
 * When the AsyncTask finishes, it calls onRefreshComplete(), which updates the data in the
 * ListAdapter and turns off the progress bar.
 *//*from   w w w  .j ava2  s.c  om*/
private void onRefreshComplete(List<String> result) {
    Log.i(LOG_TAG, "onRefreshComplete");

    // Remove all items from the ListAdapter, and then replace them with the new items
    try {
        ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter();
        adapter.clear();
        for (String cheese : result) {
            adapter.add(cheese);
        }
    } catch (ClassCastException e) {
        Log.e(LOG_TAG, e.toString());
    }

    // Stop the refreshing indicator
    setRefreshing(false);
}

From source file:com.example.android.swiperefreshlistfragment.SwipeRefreshListFragmentFragment.java

/**
 * When the AsyncTask finishes, it calls onRefreshComplete(), which updates the data in the
 * ListAdapter and turns off the progress bar.
 *//*www. ja v  a 2  s.c  o  m*/
private void onRefreshComplete(List<String> result) {
    Log.i(LOG_TAG, "onRefreshComplete");

    // Remove all items from the ListAdapter, and then replace them with the new items
    ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter();
    adapter.clear();
    for (String cheese : result) {
        adapter.add(cheese);
    }

    // Stop the refreshing indicator
    setRefreshing(false);
}

From source file:org.techbooster.app.abc.fragments.NavigationDrawerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_navigation_drawer, null, false);
    ButterKnife.inject(this, view);

    ImageView jagLink = (ImageView) inflater.inflate(R.layout.listitem_jag_link, null, false);
    mDrawerListView.addFooterView(jagLink);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from  www.j ava  2 s  . c  om
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (isClickFooterView(position)) {
                IntentUtils.openUrl(getActivity(), getString(R.string.jag_link));
                return;
            }
            selectItem(position);
        }
    });

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,
            android.R.id.text1);
    for (Menu menu : Menu.values()) {
        adapter.add(getString(menu.getTitleResId()));
    }

    mDrawerListView.setAdapter(adapter);
    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);

    return view;
}

From source file:com.appdynamics.demo.gasp.fragment.EventDetailsFragment.java

public void showEventDetails(PlaceDetail placeDetail) {
    // Use a simple TextView layout for ArrayAdapter constructor
    ArrayAdapter<String> mEventAdapter = new ArrayAdapter<String>(getActivity(), R.layout.gasp_generic_textview,
            new ArrayList<String>());
    setListAdapter(mEventAdapter);//ww w  . j a  va 2 s .c  o  m

    if (placeDetail.getEvents() != null) {
        for (PlaceEvent event : placeDetail.getEvents()) {
            Log.d(TAG, "Event Id: " + event.getEvent_id());
            Log.d(TAG, "Event Summary: " + event.getSummary());
            mEventAdapter.add(event.getSummary() + ": " + event.getUrl());
        }
    }
}

From source file:com.android.contacts.interactions.ImportDialogFragment.java

private void addItems(ArrayAdapter<AdapterEntry> adapter) {
    final Resources res = getActivity().getResources();
    if (res.getBoolean(R.bool.config_allow_import_from_vcf_file) && !mSimOnly) {
        adapter.add(new AdapterEntry(getString(R.string.import_from_vcf_file), R.string.import_from_vcf_file));
    }/*from  w ww .  j  a v  a 2  s  .  co  m*/
    final List<SimCard> sims = mSimDao.getSimCards();

    if (sims.size() == 1) {
        adapter.add(
                new AdapterEntry(getString(R.string.import_from_sim), R.string.import_from_sim, sims.get(0)));
        return;
    }
    for (int i = 0; i < sims.size(); i++) {
        final SimCard sim = sims.get(i);
        adapter.add(new AdapterEntry(getSimDescription(sim, i), R.string.import_from_sim, sim));
    }
}

From source file:com.joefernandez.irrduino.android.remote.IrrduinoRemoteActivity.java

public ArrayAdapter<SpinnerItemData> getSpinnerAdapter() {
    ArrayAdapter<SpinnerItemData> adapter = new ArrayAdapter<SpinnerItemData>(this,
            android.R.layout.simple_spinner_item);

    adapter.add(new SpinnerItemData("1 Minute", 1));
    adapter.add(new SpinnerItemData("2 Minutes", 2));
    adapter.add(new SpinnerItemData("3 Minutes", 3));
    adapter.add(new SpinnerItemData("4 Minutes", 4));
    adapter.add(new SpinnerItemData("5 Minutes", 5));
    adapter.add(new SpinnerItemData("6 Minutes", 6));
    adapter.add(new SpinnerItemData("7 Minutes", 7));
    adapter.add(new SpinnerItemData("8 Minutes", 8));
    adapter.add(new SpinnerItemData("9 Minutes", 9));
    adapter.add(new SpinnerItemData("10 Minutes", 10));

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return adapter;
}

From source file:org.mythdroid.fragments.RecEditSchedFragment.java

private void setViews() {

    dupMatchSpinner = ((Spinner) view.findViewById(R.id.dupMatch));

    final ArrayAdapter<String> dupMatchAdapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_item);
    dupMatchAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    for (RecDupMethod method : RecDupMethod.values())
        dupMatchAdapter.add(method.msg());

    dupMatchSpinner.setAdapter(dupMatchAdapter);
    if (ref.recId == 0 || ref.dupMethod == null)
        dupMatchSpinner.setSelection(dupMatchAdapter.getPosition(RecDupMethod.SUBTHENDESC.msg()));
    else//  ww  w.ja v a  2  s. c o m
        dupMatchSpinner.setSelection(ref.dupMethod.ordinal());
    dupMatchSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            ref.dupMethod = RecDupMethod.values()[pos];
            ref.checkChildren();
        }

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

    });

    dupInSpinner = ((Spinner) view.findViewById(R.id.dupIn));

    final ArrayAdapter<String> dupInAdapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_item);
    dupInAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    for (RecDupIn set : RecDupIn.values())
        dupInAdapter.add(set.msg());

    dupInSpinner.setAdapter(dupInAdapter);
    if (ref.recId == 0 || ref.dupIn == null)
        dupInSpinner.setSelection(dupInAdapter.getPosition(RecDupIn.ALL.msg()));
    else
        dupInSpinner.setSelection(ref.dupIn.ordinal());
    dupInSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            ref.dupIn = RecDupIn.values()[pos];
            ref.checkChildren();
        }

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

    });

    epiFilterSpinner = ((Spinner) view.findViewById(R.id.epiFilter));

    ArrayAdapter<String> epiFilterAdapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_item);
    epiFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    for (RecEpiFilter filter : RecEpiFilter.values())
        epiFilterAdapter.add(filter.msg());

    epiFilterSpinner.setAdapter(epiFilterAdapter);
    if (ref.epiFilter == null)
        epiFilterSpinner.setSelection(RecEpiFilter.NONE.ordinal());
    else
        epiFilterSpinner.setSelection(ref.epiFilter.ordinal());
    epiFilterSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            ref.epiFilter = RecEpiFilter.values()[pos];
            ref.checkChildren();
        }

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

    });
}