Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

In this page you can find the example usage for android.widget AdapterView getItemAtPosition.

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:es.uniovi.imovil.fcrtrainer.MainActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    int newExerciseIndex = (Integer) parent.getItemAtPosition(position);
    if (newExerciseIndex != mExerciseResIndex) {
        // Cambiar el fragmento de contenido actual
        mExerciseResIndex = newExerciseIndex;
        updateContentFragment();/*from  w w w  .j  a va2s  .c  o m*/
        mTitle = getString(mExerciseResIndex);
    }
    // Cerrar el Drawer
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:com.lillicoder.newsblurry.stories.StoriesListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Feed feed = this.getFeed();
    if (feed != null)
        this.fetchStories(feed.getId());
    else/*from www  . ja v a2 s.  co  m*/
        throw new IllegalStateException(EXCEPTION_NO_FEED_CANNOT_DISPLAY_STORIES);

    this._storiesList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Display the selected story.
            Story story = (Story) parent.getItemAtPosition(position);

            Intent displayStory = new Intent(StoriesListFragment.this.getActivity(), StoryActivity.class);
            displayStory.putExtra(StoryActivity.INTENT_STORY_TO_DISPLAY, story);

            StoriesListFragment.this.startActivity(displayStory);
        }
    });
}

From source file:fr.enst.igr201.kanmogne.iconvert.ConvertTabFragment.java

private void addListenerOnSpinners() {
    mLeftSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//from  ww  w. j  a v  a 2 s  . co  m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selectedItem = parent.getItemAtPosition(position).toString();
            Uri leftURI = CurrencyContract.Currency.buildCurrencyRateURI(selectedItem);
            mLeftRate = queryCurrencyTable(leftURI);
            //Log.w(TAG, "Letf rate : " + mLeftRate);
        }

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

        }
    });

    mRightSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selectedItem = parent.getItemAtPosition(position).toString();
            Uri rightURI = CurrencyContract.Currency.buildCurrencyRateURI(selectedItem);
            mRightRate = queryCurrencyTable(rightURI);
            //Log.w(TAG, "right rate : " + mRightRate);
        }

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

        }
    });
}

From source file:emroxriprap.com.sunshine.app.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from a source and
    // use it to populate the listview it's attached to
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.lv_foreast);
    mListView.setAdapter(mForecastAdapter);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//w  w  w. j  av  a  2s. c  o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());
                ((Callback) getActivity()).onItemSelected(WeatherContract.WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));

            }
            mPosition = position;
        }
    });
    //if theres instance state, mine it for useful info
    //the end goal here is that the user never knows that turning their device sideways
    //does crazy lifecycle related things. It should feel like some stuff stretched out,
    //or magically appeared to take advantage of room, but data or place in the app was
    //never actually "lost"
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        //the listview probably hasnt even been populated yet.  Actually perform the
        //swapout in onLoadFinished
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }
    mForecastAdapter.setnUseTodayLayout(mUseTodayLayout);
    return rootView;
}

From source file:com.app.khclub.base.easeim.activity.RobotsActivity.java

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    setContentView(R.layout.fragment_robots);
    inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mListView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light, android.R.color.holo_orange_light,
            android.R.color.holo_red_light);
    progressBar = findViewById(R.id.progress_bar);
    swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override//w  w  w.  j av a2 s .c om
        public void onRefresh() {
            getRobotNamesFromServer();
        }
    });
    Map<String, RobotUser> robotMap = ((KHHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
    if (robotMap != null) {
        robotList.addAll(robotMap.values());
    } else {
        progressBar.setVisibility(View.VISIBLE);
    }
    adapter = new RobotAdapter(this, 1, robotList);
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            RobotUser user = (RobotUser) parent.getItemAtPosition(position);
            Intent intent = new Intent();
            intent.setClass(RobotsActivity.this, ChatActivity.class);
            intent.putExtra("userId", user.getUsername());
            startActivity(intent);
        }
    });
    mListView.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (getWindow()
                    .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
                if (getCurrentFocus() != null)
                    inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
            }
            return false;
        }
    });

    getRobotNamesFromServer();
}

From source file:com.lillicoder.demo.navigationdrawer.BaseNavigationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.activity_base_navigation);

    mDrawer = (DrawerLayout) findViewById(R.id.BaseNavigationActivity_drawer);
    mNavigationList = (ListView) findViewById(R.id.BaseNavigationActivity_navigationList);
    mContentContainer = (ViewGroup) findViewById(R.id.BaseNavigationActivity_contentContainer);

    final ActionBar actionBar = getSupportActionBar();
    //actionBar.setIcon(R.drawable.ic_launcher);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Configure action bar toggling and navigation drawer look & feel
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, R.drawable.ic_drawer_light, R.string.drawer_open,
            R.string.drawer_close) {/*w w w .  java  2s  . co  m*/
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);

            getSupportActionBar().setTitle(R.string.drawer_closed_title);
            supportInvalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);

            getSupportActionBar().setTitle(R.string.drawer_opened_title);
            supportInvalidateOptionsMenu();
        }
    };
    mDrawer.setDrawerListener(mDrawerToggle);
    mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // Configure navigation list
    List<NavigationItem> navigationItems = getNavigationItems();
    NavigationListAdapter adapter = new NavigationListAdapter(navigationItems);
    mNavigationList.setAdapter(adapter);
    mNavigationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            NavigationItem item = (NavigationItem) parent.getItemAtPosition(position);
            Class<?> targetActivity = item.getTargetActivity();

            Context context = parent.getContext();

            Intent navigate = new Intent(context, targetActivity);
            if (position == 0) {
                // The top level navigation item should clear top
                navigate.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            }

            context.startActivity(navigate);
        }
    });
}

From source file:com.nma.util.sdcardtrac.GraphActivity.java

@Override
public void onCreate(Bundle savedInstance) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstance);
    setContentView(R.layout.graph);/*from  ww w.ja v  a  2 s  .  com*/

    // Setup debug logging
    SettingsActivity.ENABLE_DEBUG = pref.getBoolean(SettingsActivity.ENABLE_DEBUG_KEY, false);

    // ActionBar
    actionBar = getSupportActionBar();
    // Add a custom view with a spinner
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(R.layout.graph_action_bar);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    actionBar.addTab(actionBar.newTab().setText(TAB_NAME_EXT_STORAGE)
            .setTabListener(new GraphTabListener(this, TAB_NAME_EXT_STORAGE)));
    /*Log.d(getClass().getName(), "Creating 2");
    actionBar.addTab(actionBar.newTab().setText(TAB_NAME_INT_STORAGE)
    .setTabListener(new GraphTabListener(this, TAB_NAME_INT_STORAGE)));*/

    durationSel = (Spinner) findViewById(R.id.graph_action_bar_spinner);
    durationSel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            interval = parent.getItemAtPosition(position).toString();

            refreshGraph(true, interval);
        }

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

        }
    });

    // Help on first
    showTips = pref.getBoolean(SHOW_HELP_TAG, true);
    if (showTips) {
        showHelp();
    }

    // Start service
    alarmEnabled = pref.getBoolean(SettingsActivity.ALARM_RUNNING_KEY, false);
    boolean reInst = false;
    if (savedInstance != null) {
        Parcelable spinner;
        reInst = savedInstance.getBoolean(SettingsActivity.ALARM_RUNNING_KEY, false);
        interval = savedInstance.getString("interval", "Day");
        spinner = savedInstance.getParcelable("spinner");
        if (spinner != null)
            durationSel.onRestoreInstanceState(spinner);
    }

    if (alarmEnabled && !reInst) {
        Intent serviceIntent = new Intent(this, FileObserverService.class);
        serviceIntent.setAction(Intent.ACTION_MAIN);
        startService(serviceIntent);
    }
}

From source file:de.grobox.liberario.SetHomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_LEFT_ICON);
    setContentView(R.layout.activity_set_home);

    getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_action_home);
    setTitle(getString(R.string.home_dialog_title));

    Intent intent = getIntent();/*from ww w .j ava  2s  .co m*/

    // show new home text
    if (!intent.getBooleanExtra("new", true)) {
        findViewById(R.id.homeMsgView).setVisibility(View.GONE);
    }

    // home location TextView
    final AutoCompleteTextView homeView = (AutoCompleteTextView) findViewById(R.id.homeView);
    LocationAdapter locAdapter = new LocationAdapter(this, FavLocation.LOC_TYPE.FROM, true);
    locAdapter.setFavs(true);
    homeView.setAdapter(locAdapter);
    homeView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            Location loc = (Location) parent.getItemAtPosition(position);
            homeView.setText(loc.uniqueShortName());
            homeView.setTag(loc);
            homeView.requestFocus();

            // hide soft-keyboard
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(homeView.getWindowToken(), 0);
        }
    });

    // clear from text button
    final ImageButton homeClearButton = (ImageButton) findViewById(R.id.homeClearButton);
    homeClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            homeView.setText("");
            homeView.requestFocus();
            homeView.setTag(null);
            homeClearButton.setVisibility(View.GONE);
        }
    });

    // When text changed
    homeView.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // clear saved station
            homeView.setTag(null);

            // show clear button
            homeClearButton.setVisibility(View.VISIBLE);
        }

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }
    });

    // station name favorites button
    findViewById(R.id.homeFavButton).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            int size = ((LocationAdapter) homeView.getAdapter()).addFavs();

            if (size > 0) {
                homeView.showDropDown();
            } else {
                Toast.makeText(v.getContext(), getResources().getString(R.string.error_no_favs),
                        Toast.LENGTH_SHORT).show();
            }
        }
    });

    // OK Button
    Button okButton = (Button) findViewById(R.id.okButton);
    okButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (homeView.getTag() != null && homeView.getTag() instanceof Location) {
                // save home location in file
                FavDB.setHome(v.getContext(), (Location) homeView.getTag());

                Intent returnIntent = new Intent();
                setResult(RESULT_OK, returnIntent);

                close(v);
            } else {
                Toast.makeText(v.getContext(),
                        getResources().getString(R.string.error_only_autocomplete_station), Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    // Cancel Button
    Button cancelButton = (Button) findViewById(R.id.cancelButton);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent returnIntent = new Intent();
            setResult(RESULT_CANCELED, returnIntent);

            close(v);
        }
    });
}

From source file:com.z3r0byte.magis.PresenceActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_presence);

    mMagister = GlobalMagister.MAGISTER;

    mProfile = new Gson().fromJson(getSharedPreferences("data", MODE_PRIVATE).getString("Profile", null),
            Profile.class);
    mUser = new Gson().fromJson(getSharedPreferences("data", MODE_PRIVATE).getString("User", null), User.class);
    mSchool = new Gson().fromJson(getSharedPreferences("data", MODE_PRIVATE).getString("School", null),
            School.class);

    mToolbar = (Toolbar) findViewById(R.id.Toolbar);
    mToolbar.setTitle(R.string.title_presence);
    setSupportActionBar(mToolbar);//  w  w w. ja v a 2s  .  c  o  m

    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.layout_refresh);
    mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary, R.color.setup_color_3,
            R.color.setup_color_5);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Log.d(TAG, "onRefresh: Refreshing!");
            if (presencePeriods == null || presencePeriods[0].start == null) {
                getPresencePeriods();
            }
            getPresence();
        }
    });

    presencePeriods[0] = new PresencePeriod();
    presencePeriods[0].description = "Laden...";
    presencePeriodAdapter = new PresencePeriodAdapter(this, presencePeriods);
    spinner = (Spinner) findViewById(R.id.studyPicker);
    spinner.getBackground().setColorFilter(getResources().getColor(R.color.md_white_1000),
            PorterDuff.Mode.SRC_ATOP);
    spinner.setAdapter(presencePeriodAdapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            Log.d(TAG, "onItemSelected: PresencePeriod: " + adapterView.getItemAtPosition(i).toString());
            presencePeriod = (PresencePeriod) adapterView.getItemAtPosition(i);
            Log.d(TAG, "onItemSelected: precense date: " + presencePeriod.start);
            if (mMagister != null) {
                getPresence();
            } else {
                errorView.setVisibility(View.VISIBLE);
                errorView.setConfig(ErrorViewConfigs.NotLoggedInConfig);
            }
        }

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

        }
    });

    listView = (ListView) findViewById(R.id.list_presence);
    errorView = (ErrorView) findViewById(R.id.error_view_presence);

    navigationDrawer = new NavigationDrawer(this, mToolbar, mProfile, mUser, "Aanwezigheid");
    navigationDrawer.SetupNavigationDrawer();

    if (mMagister != null) {
        getPresencePeriods();
    } else {
        errorView.setVisibility(View.VISIBLE);
        errorView.setConfig(ErrorViewConfigs.NotLoggedInConfig);
    }
    //getPresence();
}

From source file:org.openintents.historify.ui.fragments.ContactsListFragment.java

/** Called to have the fragment instantiate its user interface view. */
@Override//from   w ww. ja  va 2s.  c  o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.fragment_contacts_list, container, false);

    // init search panel
    mSearchBar = (ViewGroup) layout.findViewById(R.id.searchBar);
    mEditSearch = (EditText) mSearchBar.findViewById(R.id.searchBar_editSearch);
    mEditSearch.setHint(R.string.searchbar_contacts_hint);

    if (savedInstanceState != null) {
        mSearchBar.setVisibility(savedInstanceState.getInt(STATE_SEARCH_VISIBILITY));
        mEditSearch.setText(savedInstanceState.getString(STATE_SEARCH_CONTENT));
    }

    mEditSearch.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void afterTextChanged(Editable s) {
            notifySearchTextChanged();
        }
    });

    mEditSearch.setOnEditorActionListener(new OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NONE) {
                if (v.getText().toString().trim().equals(""))
                    //empty search field -- so we hide it
                    onSearchSelected();
            }
            return false;
        }
    });

    // init listview
    mLstContacts = (ListView) layout.findViewById(R.id.contacts_lstContacts);
    mLstContacts.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Contact selected = (Contact) parent.getItemAtPosition(position);
            onContactSelected(selected);
        }
    });

    // init list empty view
    View lstContactsEmptyView = inflater.inflate(R.layout.list_empty_view, null);
    ((TextView) lstContactsEmptyView).setText(R.string.contacts_no_contacts);
    ((ViewGroup) mLstContacts.getParent()).addView(lstContactsEmptyView);
    mLstContacts.setEmptyView(lstContactsEmptyView);

    return layout;

}