Example usage for android.widget SpinnerAdapter getCount

List of usage examples for android.widget SpinnerAdapter getCount

Introduction

In this page you can find the example usage for android.widget SpinnerAdapter getCount.

Prototype

int getCount();

Source Link

Document

How many items are in the data set represented by this Adapter.

Usage

From source file:net.illusor.swipeplayer.activities.SwipeActivityTest.java

@SmallTest
public void testInitialBrowserState() throws Exception {
    View folderBrowserView = this.viewPager.getChildAt(1);

    DropDown dropDown = (DropDown) folderBrowserView.findViewById(R.id.id_fb_nav_history);
    assertNotNull("FolderBrowser dropdown is null", dropDown);

    SpinnerAdapter spinnerAdapter = dropDown.getAdapter();
    assertNotNull("FolderBrowser dropdown adapter is null", spinnerAdapter);
    assertEquals("FolderBrowser dropdown adapter should initially contain 1 item", 1,
            spinnerAdapter.getCount());

    ListView listView = (ListView) folderBrowserView.findViewById(R.id.id_fb_audio_files);
    assertNotNull("FolderBrowser list is null", listView);

    ListAdapter listAdapter = listView.getAdapter();
    assertNotNull("FolderBrowser list adapter is null", listAdapter);
    assertEquals("FolderBrowser list adapter should initially contain 1 item", 1, listAdapter.getCount());
}

From source file:org.catrobat.catroid.content.bricks.BroadcastWaitBrick.java

private void setSpinnerSelection(Spinner spinner) {
    int position = MessageContainer.getPositionOfMessageInAdapter(broadcastMessage);
    if (position > 0) {
        spinner.setSelection(position, true);
    } else {/*from   w w  w  . jav  a 2s.  co  m*/
        if (oldMessage != null && !oldMessage.equals("")) {
            spinner.setSelection(MessageContainer.getPositionOfMessageInAdapter(oldMessage), true);
        } else {
            SpinnerAdapter spinnerAdapter = spinner.getAdapter();
            if (spinnerAdapter != null && spinnerAdapter.getCount() > 1) {
                spinner.setSelection(1, true);
            } else {
                spinner.setSelection(0, true);
            }
        }
    }
}

From source file:org.androidui.app.ActionBarImpl.java

@Override
public int getNavigationItemCount() {
    switch (mActionView.getNavigationMode()) {
    default:// w  w w  . j av  a 2s. c om
    case ActionBar.NAVIGATION_MODE_STANDARD:
        return 0;

    case ActionBar.NAVIGATION_MODE_LIST:
        SpinnerAdapter dropdownAdapter = mActionView.getDropdownAdapter();
        return (dropdownAdapter != null) ? dropdownAdapter.getCount() : 0;

    case ActionBar.NAVIGATION_MODE_TABS:
        if (mActionView.getSelectedTab() == null) {
            return -1;
        }
        return mActionView.getTabCount();
    }
}

From source file:com.flowzr.activity.RecurActivity.java

private void editRecur(Recur recur) {
    editStartDate(recur.startDate);//w  w  w.  j  ava 2 s  .c  o  m
    RecurInterval interval = recur.interval;
    SpinnerAdapter adapter = sInterval.getAdapter();
    int count = adapter.getCount();
    for (int i = 0; i < count; i++) {
        SpinnerItem item = (SpinnerItem) adapter.getItem(i);
        if (interval == RecurInterval.valueOf(item.value)) {
            sInterval.setSelection(i);
            break;
        }
    }
    View v = selectInterval(interval);
    switch (interval) {
    case EVERY_X_DAY:
        editEveryXDay(v, recur);
        break;
    case WEEKLY:
        editWeekly(v, recur);
        break;
    case SEMI_MONTHLY:
        editSemiMonthly(v, recur);
        break;
    }
    RecurPeriod period = recur.period;
    sPeriod.setSelection(period.ordinal());
    v = selectPeriod(period);
    switch (period) {
    case EXACTLY_TIMES:
        editExactlyTimes(v, recur.periodParam);
        break;
    case STOPS_ON_DATE:
        editStopsOnDate(v, recur.periodParam);
        break;
    }
}

From source file:net.majorkernelpanic.spydroid.ClientActivity.java

/** Fetch the current streaming configuration of the remote phone **/
private void getCurrentConfiguration() {
    new AsyncTask<Void, Void, String>() {
        @Override//  www .j  a v a  2s.com
        protected String doInBackground(Void... params) {
            HttpParams httpParameters = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
            HttpConnectionParams.setSoTimeout(httpParameters, 3000);
            HttpClient client = new DefaultHttpClient(httpParameters);
            HttpGet request = new HttpGet(
                    "http://" + editTextIP.getText().toString() + ":8080/config.json?get");
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String response = "";
            try {
                response = client.execute(request, responseHandler);
            } catch (ConnectTimeoutException e) {
                Log.i(TAG, "Connection timeout ! ");
                onCompletion(null);
            } catch (Exception e) {
                Log.e(TAG, "Could not fetch current configuration on remote device !");
                e.printStackTrace();
            }
            return response;
        }

        @Override
        protected void onPostExecute(String response) {
            try {
                JSONObject object = (JSONObject) new JSONTokener(response).nextValue();
                ((CheckBox) findViewById(R.id.checkbox1)).setChecked(object.getBoolean("streamVideo"));
                ((CheckBox) findViewById(R.id.checkbox2)).setChecked(object.getBoolean("streamAudio"));
                for (int spinner : new int[] { R.id.spinner1, R.id.spinner2, R.id.spinner3, R.id.spinner4,
                        R.id.spinner5 }) {
                    Spinner view = (Spinner) findViewById(spinner);
                    SpinnerAdapter adapter = view.getAdapter();
                    for (int i = 0; i < adapter.getCount(); i++) {
                        Iterator<String> keys = object.keys();
                        while (keys.hasNext()) {
                            String key = keys.next();
                            if (adapter.getItem(i).equals(object.get(key))) {
                                view.setSelection(i);
                            }

                        }
                    }
                }
                generateURI();
                connectToServer();
            } catch (Exception e) {
                stopStreaming();
                e.printStackTrace();
            }
        }
    }.execute();
}

From source file:com.actionbarsherlock.internal.app.ActionBarImpl.java

@Override
public int getNavigationItemCount() {
    switch (mActionView.getNavigationMode()) {
    case NAVIGATION_MODE_TABS:
        return mTabs.size();
    case NAVIGATION_MODE_LIST:
        SpinnerAdapter adapter = mActionView.getDropdownAdapter();
        return adapter != null ? adapter.getCount() : 0;
    default:/*from   ww  w .  java 2 s . c  om*/
        return 0;
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsSpinner.java

int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }/*from   w ww  .  j a  v a2 s .  c  om*/

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}

From source file:android.support.v7.widget.AppCompatSpinner.java

private int compatMeasureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }// w ww .  j a v  a2s  .c  o  m

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.
    int start = Math.max(0, getSelectedItemPosition());
    final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    final int count = end - start;
    start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}

From source file:com.quran.labs.androidquran.widgets.spinner.SpinnerCompat.java

int measureContentWidth(SpinnerAdapter adapter, Drawable background) {
    if (adapter == null) {
        return 0;
    }//from  ww  w.ja v a2 s  .c o m

    int width = 0;
    View itemView = null;
    int itemType = 0;
    final int widthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    final int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);

    // Make sure the number of items we'll measure is capped. If it's a huge data set
    // with wildly varying sizes, oh well.

    // SpinnerCompat's original code looked like this:
    // int start = Math.max(0, getSelectedItemPosition());
    // final int end = Math.min(adapter.getCount(), start + MAX_ITEMS_MEASURED);
    // final int count = end - start;
    // start = Math.max(0, start - (MAX_ITEMS_MEASURED - count));
    // for Quran Android, we changed it to always take the last 15 items (or all
    // items if the total count is less than 15).

    final int end = adapter.getCount();
    int start = Math.max(end - MAX_ITEMS_MEASURED, 0);
    for (int i = start; i < end; i++) {
        final int positionType = adapter.getItemViewType(i);
        if (positionType != itemType) {
            itemType = positionType;
            itemView = null;
        }
        itemView = adapter.getView(i, itemView, this);
        if (itemView.getLayoutParams() == null) {
            itemView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        itemView.measure(widthMeasureSpec, heightMeasureSpec);
        width = Math.max(width, itemView.getMeasuredWidth());
    }

    width *= 1.1; // we add some extra space for Quran Android
    // Add background padding to measured width
    if (background != null) {
        background.getPadding(mTempRect);
        width += mTempRect.left + mTempRect.right;
    }

    return width;
}