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

The following examples show how to use android.widget.ArrayAdapter#getCount() . 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: SearchableSpinner.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        ArrayAdapter adapter = (ArrayAdapter) getAdapter();

        if (null != adapter) {

            if (_items.size() == 0) {
                for (int i = 0; i < adapter.getCount(); i++) {
                    _items.add(adapter.getItem(i));
                }
            }
            SearchableListDialog searchableListDialog = SearchableListDialog.newInstance
                    (_items);
            searchableListDialog.setOnSearchableItemClickListener(this);
            searchableListDialog.show(((Activity) _context).getFragmentManager(), "TAG");
        }
    }
    return true;
}
 
Example 2
Source File: SearchableSpinner.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        ArrayAdapter adapter = (ArrayAdapter) getAdapter();

        if (null != adapter) {

            if (_items.size() == 0) {
                for (int i = 0; i < adapter.getCount(); i++) {
                    _items.add(adapter.getItem(i));
                }
            }
            SearchableListDialog searchableListDialog = SearchableListDialog.newInstance
                    (_items);
            searchableListDialog.setOnSearchableItemClickListener(this);
            searchableListDialog.show(((Activity) _context).getFragmentManager(), "TAG");
        }
    }
    return true;
}
 
Example 3
Source File: UserMeasurementView.java    From openScale with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected View getInputView() {
    Spinner spinScaleUer = new Spinner(getContext());
    ArrayAdapter<String> spinScaleUserAdapter = new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item, new ArrayList<>());

    spinScaleUer.setAdapter(spinScaleUserAdapter);

    int spinPos = 0;

    for (ScaleUser scaleUser : openScale.getScaleUserList()) {
        spinScaleUserAdapter.add(scaleUser.getUserName());

        if (scaleUser.getId() == userId) {
            spinPos = spinScaleUserAdapter.getCount() - 1;
        }
    }

    spinScaleUer.setSelection(spinPos);

    return spinScaleUer;
}
 
Example 4
Source File: SingleChoiceDialog.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
protected final void fillList(List<T> items)
{
    final ArrayAdapter<T> adapter = initAdapter(items);
    getListView().setAdapter(adapter);
    if(adapter.getCount() > 0 && _listView.getCheckedItemPosition()<0)
        getListView().setItemChecked(0, true);
    _okButton.setEnabled(_listView.getCheckedItemPosition()>=0);
    if(_progressBar!=null)
    {
        _progressBar.setVisibility(View.GONE);
        _listView.setVisibility(View.VISIBLE);
    }
}
 
Example 5
Source File: StaticList.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param context            The current context.
 * @param resource           The resource ID for a layout file containing a layout to use when
 *                           instantiating views.
 * @param textViewResourceId The id of the TextView within the layout resource to be populated
 * @param objects            The objects to represent in the ListView.
 */
public void setAdapter(@NonNull Context context, @LayoutRes int resource,
                       @IdRes int textViewResourceId, @NonNull CharSequence[] objects) {
    ArrayAdapter<CharSequence> list = new ArrayAdapter<>(context,
            resource,
            textViewResourceId,
            objects);
    this.removeAllViews();
    for (int i = 0; i < list.getCount(); i++) {
        View item = list.getView(i, null, null);
        addView(item);
        addView(getSeparatorView());
    }
    removeViewAt(getChildCount() - 1);
}
 
Example 6
Source File: FonteGraphFragment.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void updateFunctionSpinner() {
    if (machineList.getSelectedItem() == null) return;  // List not yet initialized.
    String lMachineStr = machineList.getSelectedItem().toString();
    Machine machine = mDbMachine.getMachine(lMachineStr);
    if (machine == null) return;

    ArrayAdapter<String> adapterFunction = null;
    if (machine.getType() == ExerciseType.STRENGTH ) {
        adapterFunction = new ArrayAdapter<>(
            getContext(), android.R.layout.simple_spinner_item,
            mActivity.getResources().getStringArray(R.array.graph_functions));
    } else if (machine.getType() == ExerciseType.CARDIO) {
        adapterFunction = new ArrayAdapter<>(
            getContext(), android.R.layout.simple_spinner_item,
            mActivity.getResources().getStringArray(R.array.graph_cardio_functions));
    } else if (machine.getType() == ExerciseType.ISOMETRIC) {
        adapterFunction = new ArrayAdapter<>( getContext(), android.R.layout.simple_spinner_item,
            mActivity.getResources().getStringArray(R.array.graph_static_functions));
    }
    adapterFunction.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    functionList.setAdapter(adapterFunction);
    if (functionList.getSelectedItemPosition()!=getFunctionListPositionParams()) {
        if (getFunctionListPositionParams() <= (adapterFunction.getCount()-1)) {
            functionList.setSelection(getFunctionListPositionParams());
        }
    }
}
 
Example 7
Source File: TGBrowserView.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isSameCollection(ArrayAdapter<TGSelectableItem> c1, ArrayAdapter<TGSelectableItem> c2) {
	if( c1 == c2 ) {
		return true;
	}
	if( c1 != null && c2 != null && c1.getCount() == c2.getCount() ) {
		int count = c1.getCount();
		for(int i = 0 ; i < count ; i ++) {
			if(!this.isSameObject(c1.getItem(i), c2.getItem(i))) {
				return false;
			}
		}
		return true;
	}
	return false;
}
 
Example 8
Source File: ActivityMain.java    From nfcspy with GNU General Public License v3.0 5 votes vote down vote up
private CharSequence getAllLogs() {
	StringBuilder ret = new StringBuilder();

	final ArrayAdapter<CharSequence> messages = this.messages;
	final int count = messages.getCount();
	for (int i = 0; i < count; ++i) {
		if (i > 0)
			ret.append("\n\n");

		ret.append(messages.getItem(i));
	}

	return ret;
}
 
Example 9
Source File: SwapWorkflowActivity.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    SwitchCompat bluetoothSwitch = container.findViewById(R.id.switch_bluetooth);
    TextView textBluetoothVisible = container.findViewById(R.id.bluetooth_visible);
    TextView textDeviceIdBluetooth = container.findViewById(R.id.device_id_bluetooth);
    TextView peopleNearbyText = container.findViewById(R.id.text_people_nearby);
    ProgressBar peopleNearbyProgress = container.findViewById(R.id.searching_people_nearby);
    if (bluetoothSwitch == null || textBluetoothVisible == null || textDeviceIdBluetooth == null
            || peopleNearbyText == null || peopleNearbyProgress == null
            || !BluetoothManager.ACTION_STATUS.equals(intent.getAction())) {
        return;
    }
    int status = intent.getIntExtra(BluetoothManager.EXTRA_STATUS, -1);
    Log.i(TAG, "BluetoothManager.EXTRA_STATUS: " + status);
    switch (status) {
        case BluetoothManager.STATUS_STARTING:
            bluetoothSwitch.setEnabled(false);
            textBluetoothVisible.setText(R.string.swap_setting_up_bluetooth);
            textDeviceIdBluetooth.setVisibility(View.VISIBLE);
            peopleNearbyText.setText(R.string.swap_scanning_for_peers);
            peopleNearbyText.setVisibility(View.VISIBLE);
            peopleNearbyProgress.setVisibility(View.VISIBLE);
            break;
        case BluetoothManager.STATUS_STARTED:
            bluetoothSwitch.setEnabled(true);
            textBluetoothVisible.setText(R.string.swap_visible_bluetooth);
            textDeviceIdBluetooth.setVisibility(View.VISIBLE);
            peopleNearbyText.setText(R.string.swap_scanning_for_peers);
            peopleNearbyText.setVisibility(View.VISIBLE);
            peopleNearbyProgress.setVisibility(View.VISIBLE);
            break;
        case BluetoothManager.STATUS_STOPPING:
            bluetoothSwitch.setEnabled(false);
            textBluetoothVisible.setText(R.string.swap_stopping);
            textDeviceIdBluetooth.setVisibility(View.GONE);
            if (!BonjourManager.isAlive()) {
                peopleNearbyText.setText(R.string.swap_stopping);
                peopleNearbyText.setVisibility(View.VISIBLE);
                peopleNearbyProgress.setVisibility(View.VISIBLE);
            }
            break;
        case BluetoothManager.STATUS_STOPPED:
            bluetoothSwitch.setEnabled(true);
            textBluetoothVisible.setText(R.string.swap_not_visible_bluetooth);
            textDeviceIdBluetooth.setVisibility(View.GONE);
            if (!BonjourManager.isAlive()) {
                peopleNearbyText.setVisibility(View.GONE);
                peopleNearbyProgress.setVisibility(View.GONE);
            }

            ListView peopleNearbyView = container.findViewById(R.id.list_people_nearby);
            if (peopleNearbyView == null) {
                break;
            }
            ArrayAdapter peopleNearbyAdapter = (ArrayAdapter) peopleNearbyView.getAdapter();
            for (int i = 0; i < peopleNearbyAdapter.getCount(); i++) {
                Peer peer = (Peer) peopleNearbyAdapter.getItem(i);
                if (peer.getClass().equals(BluetoothPeer.class)) {
                    Utils.debugLog(TAG, "Removing bluetooth peer: " + peer.getName());
                    peopleNearbyAdapter.remove(peer);
                }
            }
            break;
        case BluetoothManager.STATUS_ERROR:
            bluetoothSwitch.setEnabled(true);
            textBluetoothVisible.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
            textDeviceIdBluetooth.setVisibility(View.VISIBLE);
            break;
        default:
            throw new IllegalArgumentException("Bad intent: " + intent);
    }
}
 
Example 10
Source File: Utilities.java    From rss with GNU General Public License v3.0 4 votes vote down vote up
static
void setTitlesAndDrawerAndPage(Fragment fragment, int absolutePos)
{
    String[] navTitles = s_resources.getStringArray(R.array.navigation_titles);

    if(null != fragment)
    {
        switchToFragment(fragment, false);
    }

    ListView list = s_fragmentDrawer.m_listView;
    HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) list.getAdapter();
    int headers = headerAdapter.getHeadersCount();

    int listPosition = -10 == absolutePos ? s_viewPager.getCurrentItem() + headers : absolutePos;
    int viewPagerPos = -10 == absolutePos ? s_viewPager.getCurrentItem() : absolutePos - headers;

    // Check the drawer item.
    String title = PagerAdapterTags.s_tagList.get(0);
    String subTitle = null;
    int imageRes = R.drawable.ic_action_labels;

    if(s_fragmentFavourites.isVisible())
    {
        listPosition = 0;
        title = navTitles[0];
        imageRes = R.drawable.ic_action_important;
    }
    else if(s_fragmentManage.isVisible())
    {
        listPosition = 1;
        title = navTitles[1];
        imageRes = R.drawable.ic_action_storage;
    }
    else if(s_fragmentSettings.isVisible())
    {
        listPosition = 2;
        title = navTitles[2];
        imageRes = R.drawable.ic_action_settings;
    }
    else
    {
        ArrayAdapter<String[]> adapter = (ArrayAdapter<String[]>) headerAdapter.getWrappedAdapter();

        if(null != adapter && 0 < adapter.getCount())
        {
            String[] item = adapter.getItem(viewPagerPos);
            title = item[0];
            int count = null == item[1] || item[1].isEmpty() ? 0 : Integer.parseInt(item[1]);
            String countString = s_resources.getQuantityString(R.plurals.actionbar_subtitle_unread, count, count);
            subTitle = 0 == count ? null : countString;
        }
    }
    s_actionBar.setTitle(title);
    s_actionBar.setSubtitle(subTitle);
    s_actionBar.setIcon(imageRes);

    list.setItemChecked(listPosition, true);

    // If we must change the view pager page.
    if(0 <= viewPagerPos)
    {
        // Switch the view pager page if different.
        if(s_viewPager.getCurrentItem() != viewPagerPos)
        {
            s_viewPager.setCurrentItem(viewPagerPos);
        }
    }
}