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

The following examples show how to use android.widget.ArrayAdapter#getItem() . 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: TrackIconUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public static void setIconSpinner(Spinner spinner, String iconValue) {
  @SuppressWarnings("unchecked")
  ArrayAdapter<StringBuilder> adapter = (ArrayAdapter<StringBuilder>) spinner.getAdapter();
  StringBuilder stringBuilder = adapter.getItem(0);
  stringBuilder.delete(0, stringBuilder.length());
  stringBuilder.append(iconValue);
  adapter.notifyDataSetChanged();
}
 
Example 2
Source File: ChecklistNoteActivity.java    From privacy-friendly-notes with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ArrayAdapter a = (ArrayAdapter)lvItemList.getAdapter();
    CheckListItem temp = (CheckListItem) a.getItem(position);
    temp.setChecked(!temp.isChecked());
    a.notifyDataSetChanged();
}
 
Example 3
Source File: DetailActivity.java    From KinoCast with MIT License 5 votes vote down vote up
@Override
protected void onPreExecute() {
    super.onPreExecute();
    progressDialog.show();
    //noinspection unchecked
    ArrayAdapter<Host> hosts = (ArrayAdapter<Host>) ((Spinner) findViewById(R.id.spinnerMirror)).getAdapter();
    host = hosts.getItem(((Spinner) findViewById(R.id.spinnerMirror)).getSelectedItemPosition());
    spinnerSeasonItemPosition = ((Spinner) findViewById(R.id.spinnerSeason)).getSelectedItemPosition();
    spinnerEpisodeItemPosition = ((Spinner) findViewById(R.id.spinnerEpisode)).getSelectedItemPosition();
}
 
Example 4
Source File: FolderPickerActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    @SuppressWarnings("unchecked")
    ArrayAdapter<File> adapter = (ArrayAdapter<File>) mListView.getAdapter();
    File f = adapter.getItem(i);
    if (f.isDirectory()) {
        displayFolder(f);
        invalidateOptions();
    }
}
 
Example 5
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 6
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);
        }
    }
}