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:com.mattprecious.notisync.fragment.SecondaryCustomProfileListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.custom_list, container, false);

    dbAdapter = new DbAdapter(getActivity());

    broadcastManager = LocalBroadcastManager.getInstance(getActivity());
    broadcastManager.registerReceiver(profileUpdateReceiver,
            new IntentFilter(DbAdapter.ACTION_PROFILES_UPDATED));

    listAdapter = new CustomProfileAdapter(getActivity());
    listView = (ListView) view.findViewById(R.id.list);

    View footer = inflater.inflate(R.layout.custom_footer, listView, false);
    listView.addFooterView(footer);/*from  w ww.  j a va 2  s  .  c om*/

    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(getActivity(), SecondaryCustomProfileActivity.class);

            if (position < listView.getCount() - listView.getFooterViewsCount()) {
                SecondaryProfile profile = (SecondaryProfile) parent.getItemAtPosition(position);
                intent.putExtra("profile", profile);
            }

            getActivity().startActivityForResult(intent, MainActivity.REQUEST_CODE_EDIT_PROFILE);
        }
    });

    return view;
}

From source file:org.spinsuite.view.T_Menu.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (m_IsLoadOk)
        return;/*from ww  w .jav a 2  s.co  m*/
    //   
    //   Get Params
    Bundle bundle = getActivity().getIntent().getExtras();
    if (bundle != null) {
        param = (ActivityParameter) bundle.getParcelable("Param");
    }
    if (param == null)
        param = new ActivityParameter();
    //   
    m_ActivityNo = param.getSPS_Menu_ID();
    //   Add Context
    if (m_ctx == null) {
        m_ctx = getActivity();
    }
    //   
    menu = (ListView) m_View.findViewById(R.id.lv_Menu);
    //   
    menu.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            DisplayMenuItem item = (DisplayMenuItem) adapter.getItemAtPosition(position);
            param.setParent_ID(item.getSPS_Menu_ID());
            param.setActivityMenu_ID(item.getActivityMenu_ID());
            //   Load from Action
            currentMenuItem = item;
            if (item.isSummary()) {
                //   Get Current Menu ID and Sub Title
                m_ParentArray.add(new KeyNamePair(m_CurrentParent_ID,
                        m_Callback.getActionBar().getSubtitle().toString()));
                if (m_MenuType.equals(LookupMenu.MAIN_MENU)) {
                    m_CurrentParent_ID = item.getSPS_Menu_ID();
                } else if (m_MenuType.equals(LookupMenu.SYNCHRONIZATION_MENU)) {
                    m_CurrentParent_ID = item.getSPS_SyncMenu_ID();
                }
                //   Change Title
                m_Callback.getActionBar().setSubtitle(currentMenuItem.getName());
                //   Load Data
                loadData();
            } else {
                currentOptionBundle = loadActionMenu.loadAction(item, param);
            }
        }
    });
    //   Add Context Menu
    registerForContextMenu(menu);
    //   new Menu
    lookupMenu = new LookupMenu(m_ctx, m_MenuType, conn);
    //   Action Menu Loader
    loadActionMenu = new LoadActionMenu(m_Callback, false);
    //Carlos Parada Add Support to Log for Mobile
    if (m_MenuType.equals(LookupMenu.MAIN_MENU)) {
        MSession.get(m_ctx, true);
    }
    //End Carlos Parada
    //   Set Load
    m_IsLoadOk = true;
    //   Load Data
    loadData();
}

From source file:com.udacity.sunshine.fragment.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The CursorAdapter will take data from our cursor and use it to populate the listView it's attached to
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

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

    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);

    mListView.setAdapter(mForecastAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//  w ww. j  a v  a 2s  .  c  om
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(),
            // or null if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                String locationSetting = Utility.getPreferredLocation(getActivity());

                ((Callback) getActivity()).onItemSelected(WeatherEntry
                        .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE)));
            }
            mPosition = position;
        }
    });

    // If there's instance state, mine it for useful information.
    // 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 hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    mForecastAdapter.setmUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:com.dryver.Activities.ActivityDryverMain.java

/**
 * Handles selection of various selections in the sort by spinner
 *
 * @param parent//w  ww  .  jav a 2s  .  c om
 * @param view
 * @param pos
 * @param id
 */
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    Log.i("trace", "ActivityDryverMain.onItemSelected()");
    String sortSelection = parent.getItemAtPosition(pos).toString();
    if (sortSelection.equals("All")) {
        state = ALL;
    } else if (sortSelection.equals("Pending")) {
        searchByEditText.setHint(R.string.empty);
        state = PENDING;
    } else if (sortSelection.equals("Active")) {
        searchByEditText.setHint(R.string.active);
        state = ACTIVE;
    } else if (sortSelection.equals("Geolocation")) {
        searchByEditText.setHint(R.string.meters);
        state = GEOLOCATION;
    } else if (sortSelection.equals("Keyword")) {
        searchByEditText.setHint(R.string.keyword);
        state = KEYWORD;
    } else if (sortSelection.equals("Rate")) {
        searchByEditText.setHint(R.string.rate);
        state = RATE;
    } else if (sortSelection.equals("Cost")) {
        searchByEditText.setHint(R.string.cost);
        state = COST;
    }
}

From source file:net.illusor.swipeplayer.fragments.FolderBrowserFragment.java

@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
    NavigationHistoryAdapter adapter = (NavigationHistoryAdapter) adapterView.getAdapter();
    if (this.currentDirectory == adapter.getData().get(i))
        return;//  w ww.jav a 2s . co m

    Log.d("SWIPE", this.currentDirectory.toString() + " " + i);
    File selected = (File) adapterView.getItemAtPosition(i);
    this.getSwipeActivity().openMediaDirectory(selected);

    this.navigationHistory.setSelection(adapter.getData().indexOf(this.currentDirectory));
}

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

private void setDeparturesView() {
    // station name TextView
    final AutoCompleteTextView stationView = (AutoCompleteTextView) mView.findViewById(R.id.stationView);
    LocationAdapter locAdapter = new LocationAdapter(getActivity(), FavLocation.LOC_TYPE.FROM, true);
    locAdapter.setFavs(true);/*w w w . j  a va 2 s .com*/
    stationView.setAdapter(locAdapter);
    stationView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) {
            setStation((Location) parent.getItemAtPosition(position));
            stationView.requestFocus();

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

    // clear from text button
    final ImageButton stationClearButton = (ImageButton) mView.findViewById(R.id.stationClearButton);
    stationClearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setStation(null);
            stationView.requestFocus();
        }
    });

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

            // show clear button
            if (s.length() > 0) {
                stationClearButton.setVisibility(View.VISIBLE);
            } else {
                stationClearButton.setVisibility(View.GONE);
            }
        }

        public void afterTextChanged(Editable s) {
        }

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

    // TODO adapt like in DirectionsFragment
    // station name favorites button
    OnClickListener stationViewListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            int size = ((LocationAdapter) stationView.getAdapter()).addFavs();

            if (size > 0) {
                stationView.showDropDown();
            } else {
                Toast.makeText(getActivity(), getResources().getString(R.string.error_no_favs),
                        Toast.LENGTH_SHORT).show();
            }
        }
    };
    mView.findViewById(R.id.stationFavButton).setOnClickListener(stationViewListener);
    stationView.setOnClickListener(stationViewListener);

    // home station button
    ImageButton stationHomeButton = (ImageButton) mView.findViewById(R.id.stationHomeButton);
    stationHomeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Location home = FavDB.getHome(getActivity());

            if (home != null) {
                queryForStations(home);
            } else {
                Intent intent = new Intent(getActivity(), SetHomeActivity.class);
                intent.putExtra("new", true);

                startActivityForResult(intent, MainActivity.CHANGED_HOME);
            }
        }
    });
    // Home Button Long Click
    stationHomeButton.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Intent intent = new Intent(getActivity(), SetHomeActivity.class);
            intent.putExtra("new", false);

            startActivityForResult(intent, MainActivity.CHANGED_HOME);

            return true;
        }
    });

    // Find Departures Search Button
    Button stationButton = (Button) mView.findViewById(R.id.stationButton);
    stationButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (stationView.getTag() != null && stationView.getTag() instanceof Location) {
                // use location to query departures
                Location location = (Location) stationView.getTag();

                if (!location.hasId()) {
                    Toast.makeText(getActivity(), getResources().getString(R.string.error_no_proper_station),
                            Toast.LENGTH_SHORT).show();
                    return;
                }
                queryForStations(location);
            } else {
                Toast.makeText(getActivity(),
                        getResources().getString(R.string.error_only_autocomplete_station), Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });
}

From source file:com.physphil.android.restaurantroulette.RestaurantFragment.java

private void initializeViewContent() {

    etName.setText(mRestaurant.getName());
    etName.setSelection(etName.getText().length());
    etNotes.setText(mRestaurant.getNotes());

    // Get random hint and assign it to notes field
    String[] hints = getResources().getStringArray(R.array.notes_hints);
    int i = (int) (Math.floor(Math.random() * hints.length));
    etNotes.setHint(hints[i]);/* w ww .ja v a  2s. c om*/

    // Add text watchers to update mRestaurant object when edited by user
    etName.addTextChangedListener(new TextWatcher() {

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

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

            mRestaurant.setName(s.toString());
            mUpdated = true;
            Log.d("PS", "name changed");
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    etNotes.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

            mRestaurant.setNotes(s.toString());
            mUpdated = true;
            Log.d("PS", "notes changed");
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    rbUserRating.setRating(mRestaurant.getUserRating());
    rbUserRating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

            // Set new rating every time it changes
            mRestaurant.setUserRating((int) rating);
            mUpdated = true;
            Log.d("PS", "rating changed");
        }
    });

    rbPriceLevel.setRating(mRestaurant.getPriceLevel());
    rbPriceLevel.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

            // Set new price level every time it changes
            mRestaurant.setPriceLevel((int) rating);
            mUpdated = true;
            Log.d("PS", "price changed");
        }
    });

    // Set spinner adapter and initialize.
    String[] genres = getResources().getStringArray(R.array.genres);
    spinnerGenre.setAdapter(
            new CustomFontArrayAdapter(getActivity(), android.R.layout.simple_spinner_dropdown_item, genres));
    spinnerGenre.setSelection(getIndex(spinnerGenre, mRestaurant.getGenre()), false);

    // Add listener to set genre when changed
    spinnerGenre.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

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

            mRestaurant.setGenre((String) spinner.getItemAtPosition(position));
            mUpdated = true;
            Log.d("PS", "genre changed");
        }

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

    // Get directions button
    btnDirections.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            //showOnMap();
            //Util.showOnMap(getActivity(), mRestaurant.getName());
            mLocationHelper.connectAndGetLocation();
        }
    });
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from our cursor and populate the ListView.
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);
    mForecastAdapter.setUseTodayLayout(mUseTodayLayout);

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

    View emptyView = rootView.findViewById(R.id.listview_forecast_empty);
    // Get a reference to the ListView, and attach this adapter to it.
    mListView = (ListView) rootView.findViewById(R.id.listview_forecast);
    mListView.setEmptyView(emptyView);//from w w w . j a  v a2 s .co  m
    mListView.setAdapter(mForecastAdapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            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 there's instance state, mine it for useful information.
    // 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 hasn't even been populated yet.  Actually perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

From source file:edu.mit.mobile.android.locast.itineraries.ItineraryDetail.java

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

    final Cursor cast = (Cursor) adapter.getItemAtPosition(position);
    final int dratCol = cast.getColumnIndex(Cast._DRAFT);
    final boolean isDraft = !cast.isNull(dratCol) && cast.getInt(dratCol) == 1;

    if (isDraft) {
        startActivity(new Intent(Intent.ACTION_EDIT, ContentUris.withAppendedId(mCastsUri, id)));
    } else {//from w  ww  . j  a v a2s  .c o m
        startActivity(new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId(mCastsUri, id)));
    }
}

From source file:name.marinchenko.lorryvision.activities.main.MainActivity.java

@Override
    public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
        final LoginDialog dialog = new LoginDialog();
        final Bundle bundle = new Bundle();

        final String id = ((Net) adapterView.getItemAtPosition(i)).getSsid();

        bundle.putString(EXTRA_NET_SSID, id);
        dialog.setArguments(bundle);/*from  ww w .  j  a v a  2  s. c  o  m*/
        dialog.show(getFragmentManager(), "login");

        return true;
    }