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:org.spinsuite.view.LV_Search.java

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    super.setContentView(R.layout.v_search);
    //   Get Field
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        m_field = (InfoField) bundle.getParcelable("Field");
        m_SFA_Table_ID = bundle.getInt("SFA_Table_ID");
        m_SFA_Tab_ID = bundle.getInt("SFA_Tab_ID");
        m_criteria = bundle.getParcelable("Criteria");
    }//ww  w .  j  ava 2s.c  o m
    //   
    if (m_field == null)
        m_field = new InfoField();
    //   
    llc_Search = (LinearLayout) findViewById(R.id.llc_Search);
    lv_Search = (ListView) findViewById(R.id.lv_Search);
    //   
    if (m_SFA_Table_ID != 0)
        lookup = new LookupDisplayType(getApplicationContext(), m_SFA_Table_ID);
    else if (m_field != null)
        lookup = new LookupDisplayType(getApplicationContext(), m_field);

    loadConfig();

    //   Load
    load();
    //   Listener
    lv_Search.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            //   Load from Action
            selectedRecord((DisplayRecordItem) adapter.getItemAtPosition(position));
        }
    });
}

From source file:oss.ridendivideapp.TakeRideActivity.java

public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    if (view == tkr_frm_acView) {
        tkr_frm_addr = (String) adapterView.getItemAtPosition(position);
    } else if (view == tkr_to_acView) {
        tkr_to_addr = (String) adapterView.getItemAtPosition(position);
    }//from ww w . j a v a2 s  .c o m
}

From source file:com.permutassep.presentation.view.wizard.ui.ProfessorCityToFragment.java

private void setupSpinners() {

    if (spnState.getAdapter() == null) {
        String[] states = getResources().getStringArray(R.array.states);
        for (short i = 0; i < states.length; i++) {
            mStates.add(new State(i, states[i]));
        }/*from  w ww.j  a v a  2s.  c om*/
        spnState.setAdapter(new PlaceSpinnerBaseAdapter(getActivity(), mStates));
    }

    spnState.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            State selectedState = (State) parent.getItemAtPosition(position);
            if (position != stateSelectedPosition && selectedState.getId() != 0) {

                showDialog(getString(R.string.please_wait), getString(R.string.main_loading_cities));
                // Remove localities
                resetSpinner(spnLocality);
                mCities.clear();
                mTowns.clear();
                stateSelectedPosition = position;
                citySelectedPosition = 0;
                townSelectedPosition = 0;
                mPage.getData().putParcelable(ProfessorCityToPage.STATE_TO_DATA_KEY, selectedState);
                mPage.getData().remove(ProfessorCityToPage.MUNICIPALITY_TO_DATA_KEY);
                mPage.getData().remove(ProfessorCityToPage.LOCALITY_TO_DATA_KEY);
                mPage.notifyDataChanged();

                try {
                    InegiFacilRestClient.get().getCities(String.valueOf(selectedState.getId()),
                            new Callback<ArrayList<City>>() {
                                @Override
                                public void success(ArrayList<City> cities, Response response) {
                                    mCities = cities;
                                    spnMunicipality
                                            .setAdapter(new PlaceSpinnerBaseAdapter(getActivity(), cities));
                                    hideDialog();
                                }

                                @Override
                                public void failure(RetrofitError error) {
                                    hideDialog();
                                }
                            });

                } catch (Exception ex) {
                    Log.d("An error ocurred", ex.getMessage());
                }
            } else {
                if (selectedState.getId() == 0) {
                    resetSpinner(spnMunicipality);
                    resetSpinner(spnLocality);
                }
            }
        }

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

    spnMunicipality.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            City selectedCity = (City) parent.getItemAtPosition(position);
            if (citySelectedPosition != position && position != 0 && getUserVisibleHint()) {

                showDialog(getString(R.string.please_wait), getString(R.string.main_loading_localities));
                mTowns.clear();
                citySelectedPosition = position;
                townSelectedPosition = 0;
                mPage.getData().putParcelable(ProfessorCityToPage.MUNICIPALITY_TO_DATA_KEY, selectedCity);
                mPage.getData().remove(ProfessorCityToPage.LOCALITY_TO_DATA_KEY);
                mPage.notifyDataChanged();

                try {
                    InegiFacilRestClient.get().getTowns(String.valueOf(selectedCity.getClaveEntidad()),
                            String.valueOf(selectedCity.getClaveMunicipio()), new Callback<ArrayList<Town>>() {
                                @Override
                                public void success(ArrayList<Town> towns, Response response) {
                                    mTowns = towns;
                                    spnLocality.setAdapter(new PlaceSpinnerBaseAdapter(getActivity(), towns));
                                    hideDialog();
                                }

                                @Override
                                public void failure(RetrofitError error) {
                                    hideDialog();
                                }
                            });

                } catch (Exception ex) {
                    Log.d("An error occurred", ex.getMessage());
                }
            } else {
                if (position != 0) {
                    resetSpinner(spnLocality);
                }
            }
        }

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

    spnLocality.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            Town town = (Town) parent.getItemAtPosition(position);
            townSelectedPosition = position;
            mPage.getData().putParcelable(ProfessorCityToPage.LOCALITY_TO_DATA_KEY, town);
            mPage.notifyDataChanged();
        }

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

        }
    });
}

From source file:com.stephenmcgruer.simpleupnp.fragments.FileBrowserFragment.java

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    FileBrowserAdapter.ListItem listItem = (FileBrowserAdapter.ListItem) adapterView
            .getItemAtPosition(position);
    if (listItem.isPreviousContainerListItem()) {
        onBackPressed();/*from   w  w  w . j  a va 2  s .c o  m*/
    } else if (listItem.holdsContainer()) {
        selectContainer(listItem.getContainer());
    } else {
        List<Item> items = new ArrayList<>();
        items.add(listItem.getItem());
        playItems(items);
    }
}

From source file:com.permutassep.presentation.view.wizard.ui.ProfessorCityFromFragment.java

private void setupSpinners() {

    if (spnState.getAdapter() == null) {
        String[] states = getResources().getStringArray(R.array.states);
        for (short i = 0; i < states.length; i++) {
            mStates.add(new State(i, states[i]));
        }// w ww. j  a v a2s.  c  o  m
        spnState.setAdapter(new PlaceSpinnerBaseAdapter(getActivity(), mStates));
    }

    spnState.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            State selectedState = (State) parent.getItemAtPosition(position);
            if (position != stateSelectedPosition && selectedState.getId() != 0) {

                showDialog(getString(R.string.please_wait), getString(R.string.main_loading_cities));
                // Remove localities
                resetSpinner(spnLocality);
                mCities.clear();
                mTowns.clear();
                stateSelectedPosition = position;
                citySelectedPosition = 0;
                townSelectedPosition = 0;
                mPage.getData().putParcelable(ProfessorCityFromPage.STATE_DATA_KEY, selectedState);
                mPage.getData().remove(ProfessorCityFromPage.MUNICIPALITY_DATA_KEY);
                mPage.getData().remove(ProfessorCityFromPage.LOCALITY_DATA_KEY);
                mPage.notifyDataChanged();

                try {
                    InegiFacilRestClient.get().getCities(String.valueOf(selectedState.getId()),
                            new Callback<ArrayList<City>>() {
                                @Override
                                public void success(ArrayList<City> cities, Response response) {
                                    mCities = cities;
                                    spnMunicipality
                                            .setAdapter(new PlaceSpinnerBaseAdapter(getActivity(), cities));
                                    hideDialog();
                                }

                                @Override
                                public void failure(RetrofitError error) {
                                    hideDialog();
                                }
                            });

                } catch (Exception ex) {
                    Log.d("An error ocurred", ex.getMessage());
                }
            } else {
                if (selectedState.getId() == 0) {
                    resetSpinner(spnMunicipality);
                    resetSpinner(spnLocality);
                }
            }
        }

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

    spnMunicipality.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            City selectedCity = (City) parent.getItemAtPosition(position);
            if (citySelectedPosition != position && position != 0 && getUserVisibleHint()) {

                showDialog(getString(R.string.please_wait), getString(R.string.main_loading_localities));
                mTowns.clear();
                citySelectedPosition = position;
                townSelectedPosition = 0;
                mPage.getData().putParcelable(ProfessorCityFromPage.MUNICIPALITY_DATA_KEY, selectedCity);
                mPage.getData().remove(ProfessorCityFromPage.LOCALITY_DATA_KEY);
                mPage.notifyDataChanged();

                try {
                    InegiFacilRestClient.get().getTowns(String.valueOf(selectedCity.getClaveEntidad()),
                            String.valueOf(selectedCity.getClaveMunicipio()), new Callback<ArrayList<Town>>() {
                                @Override
                                public void success(ArrayList<Town> towns, Response response) {
                                    mTowns = towns;
                                    spnLocality.setAdapter(new PlaceSpinnerBaseAdapter(getActivity(), towns));
                                    hideDialog();
                                }

                                @Override
                                public void failure(RetrofitError error) {
                                    hideDialog();
                                }
                            });

                } catch (Exception ex) {
                    Log.d("An error occurred", ex.getMessage());
                }
            } else {
                if (position != 0) {
                    resetSpinner(spnLocality);
                }
            }
        }

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

    spnLocality.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            Town town = (Town) parent.getItemAtPosition(position);
            townSelectedPosition = position;
            mPage.getData().putParcelable(ProfessorCityFromPage.LOCALITY_DATA_KEY, town);
            mPage.notifyDataChanged();
        }

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

        }
    });
}

From source file:com.svpino.longhorn.activities.DashboardActivity.java

private void performSearch(String query) {
    this.stockListFragment.hideContextualActionBar();
    Cursor cursor = DataProvider.search(getApplicationContext(), query);

    if (this.searchDialog == null || !this.searchDialog.isShowing()) {
        this.searchDialog = new Dialog(this);
        this.searchDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.searchDialog.setContentView(R.layout.dialog);

        TextView messageTextView = (TextView) this.searchDialog.findViewById(R.id.messageTextView);
        TextView titleTextView = (TextView) this.searchDialog.findViewById(R.id.titleTextView);

        ListView listView = (ListView) this.searchDialog.findViewById(R.id.listView);

        if (cursor != null && cursor.getCount() > 0) {
            titleTextView.setText(String.format(getString(R.string.dialog_search_title), query));
            messageTextView.setVisibility(View.GONE);

            String[] from = new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1,
                    SearchManager.SUGGEST_COLUMN_TEXT_2, LonghornDatabase.KEY_EXCHANGE_SYMBOL };
            int[] to = new int[] { R.id.nameTextView, R.id.descriptionTextView, R.id.additionalTextView };

            SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.dialog_item,
                    cursor, from, to, 0);
            adapter.setViewBinder(new ViewBinder() {

                @Override//from w w  w .j a va  2s  . c  o  m
                public boolean setViewValue(View view, Cursor cursor, int columnIndex) {

                    if (columnIndex == 0) {
                        ((View) view.getParent()).setTag(cursor.getString(columnIndex));
                    }

                    return false;
                }
            });

            listView.setAdapter(adapter);

            listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                    Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
                    addStockToWatchList(cursor.getString(0));
                    DashboardActivity.this.searchDialog.dismiss();
                }
            });
        } else {
            titleTextView.setText(getString(R.string.dialog_search_empty_title));
            messageTextView.setText(String.format(getString(R.string.dialog_search_empty_message), query));
            messageTextView.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
        }

        this.searchDialog.show();
    }
}

From source file:com.seamusdawkins.autocomplete.MainActivity.java

public void onItemClick(AdapterView adapterView, View view, int position, long id) {
    hideKeyboard();//from   w w  w .  ja  v a 2s  .  co  m

    description = (String) adapterView.getItemAtPosition(position);
    Toast.makeText(this, description, Toast.LENGTH_SHORT).show();

    String reference = (String) resultListReference.get(position);
    String urlLocate = "https://maps.googleapis.com/maps/api/place/details/json?key="
            + getString(R.string.google_server_key) + "&reference=" + reference;
    AsyncTaskNewsParseJson myTask = new AsyncTaskNewsParseJson();
    myTask.execute(urlLocate);

    autoCompView.setText("");

}

From source file:com.udacity.android.student.project.app.CatalogFragment.java

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

    // The CourseAdapter will take data from a source and
    // use it to populate the ListView it's attached to.
    mCourseAdapter = new CourseAdapter(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.listview_catalog);
    mListView.setAdapter(mCourseAdapter);
    // We'll call our MainActivity

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override/*from w w w . j  a  v  a2s . c o  m*/
        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 selectedCode = CODE.getString(cursor);
                Uri uriForActivityDetails = buildCourseUri(selectedCode);

                Log.i(LOG_TAG, "SELECTED " + selectedCode + " uri " + uriForActivityDetails);

                ((Callback) getActivity()).onItemSelected(uriForActivityDetails);

            }
            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:com.benakin100.android.sunshine.app.ForecastFragment.java

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

    // The ForecastAdapter 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.listview_forecast);
    mListView.setAdapter(mForecastAdapter);
    // We'll call our MainActivity
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override/*www . jav a2  s .  c  o m*/
        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*. ahhh fuck it
    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.setUseTodayLayout(mUseTodayLayout);

    return rootView;
}

From source file:dev.coatl.co.urband_basic.presenter.activities.StartSearchDevice.java

private void setResources() {
    handler = new Handler();
    listDevices = (ListView) findViewById(R.id.urband_device_list);
    listDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from  w ww .ja  v a 2  s  .co  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final BluetoothDevice device = ((BluetoothUrbandDeviceItem) parent.getItemAtPosition(position))
                    .getDevice();
            if (device == null) {
                return;
            }
            intent = new Intent(getApplicationContext(), ActivityHomePanel.class);
            intent.putExtra(EXTRAS_DEVICE_NAME, device.getName());
            intent.putExtra(EXTRAS_DEVICE_ADDRESS, device.getAddress());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (scanning) {
                bluetoothAdapter.stopLeScan(scanDevices);
                scanning = false;
            }
            startActivity(intent);
        }
    });
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, "Este dispositivo no soporta Bluetooth", Toast.LENGTH_SHORT).show();
        finish();
    }
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    bluetoothAdapter = bluetoothManager.getAdapter();
}