Example usage for android.widget ListAdapter getItem

List of usage examples for android.widget ListAdapter getItem

Introduction

In this page you can find the example usage for android.widget ListAdapter getItem.

Prototype

Object getItem(int position);

Source Link

Document

Get the data item associated with the specified position in the data set.

Usage

From source file:at.bitfire.davdroid.syncadapter.SelectCollectionsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.next:
        ServerInfo serverInfo = (ServerInfo) getArguments().getSerializable(KEY_SERVER_INFO);

        // synchronize only selected collections
        for (ServerInfo.ResourceInfo addressBook : serverInfo.getAddressBooks())
            addressBook.setEnabled(false);
        for (ServerInfo.ResourceInfo calendar : serverInfo.getCalendars())
            calendar.setEnabled(false);// w  ww .j a  v a2s  .c om

        ListAdapter adapter = getListView().getAdapter();
        for (long id : getListView().getCheckedItemIds()) {
            int position = (int) id + 1; // +1 because header view is inserted at pos. 0 
            ServerInfo.ResourceInfo info = (ServerInfo.ResourceInfo) adapter.getItem(position);
            info.setEnabled(true);
        }

        // pass to "account details" fragment
        AccountDetailsFragment accountDetails = new AccountDetailsFragment();
        Bundle arguments = new Bundle();
        arguments.putSerializable(SelectCollectionsFragment.KEY_SERVER_INFO, serverInfo);
        accountDetails.setArguments(arguments);

        getFragmentManager().beginTransaction().replace(R.id.fragment_container, accountDetails)
                .addToBackStack(null).commitAllowingStateLoss();
        break;
    default:
        return false;
    }
    return true;
}

From source file:org.droidupnp.view.SettingsActivity.java

public void setListAdapter(ListAdapter adapter) {
    if (mHeaders == null) {
        mHeaders = new ArrayList<Header>();
        for (int i = 0; i < adapter.getCount(); ++i)
            mHeaders.add((Header) adapter.getItem(i));
    }// w  w w .j  a  v a 2s  .  co  m
    super.setListAdapter(new MyPrefsHeaderAdapter(this, mHeaders));
}

From source file:com.oakesville.mythling.prefs.PrefsActivity.java

@Override
public void setListAdapter(ListAdapter adapter) {
    if (headers == null) {
        headers = new ArrayList<Header>();
        // when the saved state provides the list of headers, onBuildHeaders() is not called
        // so we build it from the adapter provided, then use our own adapter

        for (int i = 0; i < adapter.getCount(); i++)
            headers.add((Header) adapter.getItem(i));
    }//from w w  w.  ja  v  a  2s  .  com

    super.setListAdapter(new HeaderListAdapter(this, headers));
}

From source file:piuk.blockchain.android.ui.WalletTransactionsFragment.java

@Override
public boolean onContextItemSelected(final MenuItem item) {
    final AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    final ListAdapter adapter = ((ListView) lastContextMenuView).getAdapter();
    final MyTransaction tx = (MyTransaction) adapter.getItem(menuInfo.position);

    switch (item.getItemId()) {
    case R.id.wallet_transactions_context_edit_address:
        editAddress(tx);//from  w  w  w.  j a  va2  s.  c  o m
        return true;
    default:
        return false;
    }
}

From source file:com.probam.updater.activity.GooActivity.java

@SuppressWarnings("deprecation")
@Override/* w  w  w  . j a  v a2s .  c  o m*/
protected void onCreate(Bundle savedInstanceState) {

    boolean useDarkTheme = ManagerFactory.getPreferencesManager(this).isDarkTheme();
    setTheme(useDarkTheme ? R.style.DarkTheme : R.style.AppTheme);

    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.layout.empty_pref_screen);

    PreferenceScreen pScreen = getPreferenceScreen();
    mInfos = new HashMap<String, PackageInfo>();

    if (CURRENT_NAVIGATION == null) {

        Preference preference = null;

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", false);
        preference.getExtras().putBoolean("FOLDER", true);
        preference.getExtras().putString("PATH", "/devs");
        preference.setKey(Constants.GOO_SEARCH_URL + "/devs&ro_board=" + mDevice);
        preference.setTitle(R.string.goo_browse_all_compatible);
        pScreen.addPreference(preference);

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", true);
        preference.getExtras().putBoolean("FOLDER", true);
        preference.getExtras().putString("PATH", "/devs");
        preference.setKey(Constants.GOO_SEARCH_URL + "/devs");
        preference.setTitle(R.string.goo_browse_all);
        pScreen.addPreference(preference);

        preference = new Preference(this);
        preference.getExtras().putBoolean("BROWSING_ALL", false);
        preference.getExtras().putBoolean("FOLDER", false);
        preference.getExtras().putString("PATH", "");
        preference.setKey("watchlist");
        preference.setTitle(R.string.goo_browse_watchlist);
        pScreen.addPreference(preference);

    } else {

        if ("watchlist".equals(CURRENT_FOLDER)) {

            PreferenceCategory category = new PreferenceCategory(this);
            category.setKey("category");
            category.setTitle(
                    getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER }));
            pScreen.addPreference(category);
            refreshWatchlist();
        } else {

            PreferenceCategory category = new PreferenceCategory(this);
            category.setTitle(
                    getResources().getString(R.string.goo_category_title, new Object[] { CURRENT_FOLDER }));
            pScreen.addPreference(category);
            try {

                JSONObject object = (JSONObject) new JSONTokener(CURRENT_NAVIGATION).nextValue();
                JSONArray list = object.getJSONArray("list");

                for (int i = 0; i < list.length(); i++) {

                    JSONObject result = list.getJSONObject(i);
                    String fileName = result.optString("filename");

                    if (fileName != null && !"".equals(fileName.trim())) {

                        String path = result.optString("path");

                        if (!BROWSING_ALL && !mDevice.equals(result.optString("ro_board"))) {
                            continue;
                        }

                        GooPackage info = new GooPackage(result, -1);
                        mInfos.put(path, info);

                        Preference preference = new Preference(this);
                        preference.getExtras().putBoolean("FOLDER", false);
                        preference.setKey(path);
                        preference.setTitle(fileName);
                        preference.setSummary(path);
                        category.addPreference(preference);

                    } else {

                        String folder = result.optString("folder");
                        String folderName = folder.substring(folder.lastIndexOf("/") + 1);

                        Preference preference = new FolderPreference(this, folder, false);
                        preference.getExtras().putBoolean("BROWSING_ALL", BROWSING_ALL);
                        preference.getExtras().putBoolean("FOLDER", true);
                        preference.getExtras().putString("PATH", folder);
                        if (!BROWSING_ALL) {
                            preference.setKey(Constants.GOO_SEARCH_URL + folder + "&ro_board=" + mDevice);
                        } else {
                            preference.setKey(Constants.GOO_SEARCH_URL + folder);
                        }
                        preference.setTitle(folderName);
                        preference.setSummary(folder);
                        category.addPreference(preference);
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                Toast.makeText(this, R.string.goo_browse_error, Toast.LENGTH_LONG).show();
            }
        }
    }
    if (DIALOG != null)
        DIALOG.dismiss();

    DIALOG = null;

    ListView listView = getListView();
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            ListAdapter listAdapter = listView.getAdapter();
            Object obj = listAdapter.getItem(position);
            if (obj != null && obj instanceof View.OnLongClickListener) {
                View.OnLongClickListener longListener = (View.OnLongClickListener) obj;
                return longListener.onLongClick(view);
            }
            return false;
        }
    });
}

From source file:android.support.v7.view.menu.MenuPopup.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    ListAdapter outerAdapter = (ListAdapter) parent.getAdapter();
    MenuAdapter wrappedAdapter = toMenuAdapter(outerAdapter);

    // Use the position from the outer adapter so that if a header view was added, we don't get
    // an off-by-1 error in position.
    wrappedAdapter.mAdapterMenu.performItemAction((MenuItem) outerAdapter.getItem(position), this, // always make sure that we show the sub-menu
            closeMenuOnSubMenuOpened() ? 0 : SupportMenu.FLAG_KEEP_OPEN_ON_SUBMENU_OPENED);
}

From source file:com.zphinx.sortattributes.SortDialogManager.java

/**
 * A listener used to fire the sorting action promoted by this dialog
 *
 * @param adapter/*from  ww  w.ja va  2s  .c om*/
 *            The adapter associated with the list of state textview objects
 * @return A click listener used to sort data in the associated activity
 */
private OnClickListener sortListener(final ListAdapter adapter, final Activity activity) {
    return new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            StateTextView stv = (StateTextView) adapter.getItem(selectedIndex);
            Log.d(TAG, "The stateView is: ........................." + stv + "at position: " + selectedIndex);
            if (stv != null) {
                // currently not checking for changes??
                int direction = stv.getSortDirection();
                MainActivity.sortIndex = selectedIndex + 1;
                MainActivity.sortDirection = direction;
                ((MainActivity) activity).fireSorter();
            }
            alertDialog.dismiss();
        }
    };
}

From source file:de.tum.in.tumcampus.fragments.SettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);

    mContext = getActivity();//from w  w  w. j  a va  2 s  .  co  m

    // Disables silence service if the app is used without TUMOnline access
    CheckBoxPreference silent = (CheckBoxPreference) findPreference("silent_mode");
    if (!new AccessTokenManager(mContext).hasValidAccessToken()) {
        silent.setEnabled(false);
    }

    // Click listener for preference list entries. Used to simulate a button
    // (since it is not possible to add a button to the preferences screen)
    findPreference("button_wizard").setOnPreferenceClickListener(this);
    findPreference("button_clear_cache").setOnPreferenceClickListener(this);
    findPreference("facebook").setOnPreferenceClickListener(this);
    findPreference("github").setOnPreferenceClickListener(this);
    findPreference("first_run").setOnPreferenceClickListener(this);
    findPreference("licenses").setOnPreferenceClickListener(this);
    findPreference("feedback").setOnPreferenceClickListener(this);
    findPreference("privacy").setOnPreferenceClickListener(this);

    // Set summary for these preferences
    setSummary("card_cafeteria_default_G");
    setSummary("card_cafeteria_default_K");
    setSummary("card_cafeteria_default_W");
    setSummary("card_role");
    setSummary("card_stations_default_G");
    setSummary("card_stations_default_C");
    setSummary("card_stations_default_K");
    setSummary("card_default_campus");
    setSummary("silent_mode_set_to");
    setSummary("background_mode_set_to");

    // Register the change listener to react immediately on changes
    PreferenceManager.getDefaultSharedPreferences(mContext).registerOnSharedPreferenceChangeListener(this);

    // Populate news sources
    populateNewsSources();

    // Open a card's preference screen if selected from it's context menu
    Bundle bundle = getArguments();
    if (bundle != null && bundle.containsKey(Const.PREFERENCE_SCREEN)) {
        final String key = bundle.getString(Const.PREFERENCE_SCREEN);

        PreferenceScreen screen = (PreferenceScreen) findPreference("cards_pref_container");
        final PreferenceScreen cardPreferenceScreen = (PreferenceScreen) findPreference(key);
        cardPreferenceScreen.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                initializeActionBar(cardPreferenceScreen);
                return true;
            }
        });

        final ListAdapter listAdapter = screen.getRootAdapter();
        final int itemsCount = listAdapter.getCount();
        for (int i = 0; i < itemsCount; ++i) {
            if (listAdapter.getItem(i).equals(cardPreferenceScreen)) {
                screen.onItemClick(null, null, i, 0);
                break;
            }
        }
    }
}

From source file:dev.drsoran.moloko.fragments.AbstractTasksListFragment.java

@Override
public T getTask(String taskId) {
    T task = null;//from w  ww .j ava 2 s .co  m

    final ListAdapter adapter = getListAdapter();
    final int itemCount = adapter.getCount();
    for (int i = 0; i < itemCount && task == null; i++) {
        @SuppressWarnings({ "unchecked" })
        final T temp = (T) adapter.getItem(i);
        if (temp.getId().equals(taskId)) {
            task = temp;
        }
    }

    return task;
}