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.sensapp.android.sensappdroid.activities.GraphDisplayerActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graph_displayer);

    List<String> data = getIntent().getData().getPathSegments();
    graphName = data.get(data.size() - 1);
    graphID = Long.parseLong(data.get(data.size() - 2));

    setTitle(graphName);//ww  w .  j ava 2 s. co m

    ListView list = (ListView) findViewById(R.id.list_graph_displayer);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            GraphWrapper gw = (GraphWrapper) adapterView.getItemAtPosition(i);
            Callable<Integer> refreshGraphs = new Callable<Integer>() {
                public Integer call() {
                    return displayGraphs();
                }
            };
            GraphSensorOptionsDialogFragment.newInstance(gw.getID(), gw.getName(), refreshGraphs)
                    .show(getSupportFragmentManager(), "newOptionEditor");
        }
    });

    list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            GraphWrapper gw = (GraphWrapper) adapterView.getItemAtPosition(i);
            String where = SensAppContract.GraphSensor.ID + " = \"" + gw.getID() + "\" AND "
                    + SensAppContract.GraphSensor.GRAPH + " = " + graphID;
            getApplication().getContentResolver().delete(SensAppContract.GraphSensor.CONTENT_URI, where, null);
            displayGraphs();
            return true;
        }
    });

    getSupportLoaderManager().initLoader(0, null, this);

    displayGraphs();
}

From source file:com.example.manuelseguranavarro.eltiempo.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/*w w w  .  ja  v  a  2s . co  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)));
            }
            mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
            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.example.vivek.team.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the gender of the user.
 */// w w w . j a  v a2  s  .  co  m
private void setupSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options,
            android.R.layout.simple_spinner_item);

    // Specify dropdown layout style - simple list view with 1 item per line
    genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    // Apply the adapter to the spinner
    mGenderSpinner.setAdapter(genderSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mGenderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selection = (String) parent.getItemAtPosition(position);
            if (!TextUtils.isEmpty(selection)) {
                if (selection.equals(getString(R.string.gender_male))) {
                    mGender = GENDER_MALE; // Male
                } else if (selection.equals(getString(R.string.gender_female))) {
                    mGender = GENDER_FEMALE; // Female
                } else {
                    mGender = GENDER_SELECT;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mGender = 0; // Unknown
        }
    });
}

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

/**
 * Load Drawer//from  w  w  w.jav a  2 s .c  om
 * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 14/03/2014, 09:23:22
 * @return void
 */
protected void loadDrawer() {
    //   
    m_DLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    //   
    m_DList = (ListView) findViewById(R.id.left_drawer);
    //   
    m_DLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    m_DList.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            //   Selected Option
            onSelectedDrawerOption((DisplayMenuItem) adapter.getItemAtPosition(position));
        }
    });

    m_DToggle = new ActionBarDrawerToggle(this, m_DLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {

        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };
    //   Set Toggle
    m_DLayout.setDrawerListener(m_DToggle);
    //   
    isDrawerLoaded = true;
}

From source file:com.example.venkatagovardhan.docorganizer.FolderActivity.java

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    switch (arg0.getId()) {
    case R.id.listNavigation:
        NavDrawerItem item = (NavDrawerItem) arg0.getItemAtPosition(arg2);
        if (item.onClicked(this))
            drawerLayout.closeDrawers();
        break;//from  w  ww  .j a  v a  2s .c  o  m

    case R.id.listClipboard:
        FolderFragment folderFragment = getFolderFragment();
        if (folderFragment != null) {
            // TODO: paste single file
        }
        break;

    default:
        break;
    }
}

From source file:com.tianyu.android.weatherrocks.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);

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from w ww. j ava2 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*.
    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:com.github.jvanhie.discogsscrobbler.ReleaseListActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("enable_discogs", true)) {
        // Inflate the menu; this adds items to the action bar if it is present.
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.discogs_list, menu);
        //configure search box
        final MenuItem search = menu.findItem(R.id.list_search);
        SearchView searchView = (SearchView) search.getActionView();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override//from  w w w  . ja v  a 2 s.  c o m
            public boolean onQueryTextSubmit(String s) {
                menu.findItem(R.id.list_search).collapseActionView();
                return false;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                mReleaseList.filter(s);
                return false;
            }
        });
        searchView.setQueryHint("Filter your releases");
        final MenuItem filter = menu.findItem(R.id.list_filter);
        if (!mFolders) {
            mDiscogs.getFolders(new Discogs.DiscogsDataWaiter<List<Folder>>() {
                @Override
                public void onResult(boolean success, List<Folder> data) {
                    if (success && data != null) {
                        mFolders = true;
                        Spinner s = (Spinner) filter.getActionView(); // find the spinner
                        ArrayAdapter<Folder> mSpinnerAdapter = new ArrayAdapter<Folder>(
                                getSupportActionBar().getThemedContext(),
                                android.R.layout.simple_spinner_dropdown_item, data);
                        mSpinnerAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
                        s.setAdapter(mSpinnerAdapter); // set the adapter
                        s.setSelection(0, false);
                        s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                            @Override
                            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                                mDiscogs.setFolderId(((Folder) adapterView.getItemAtPosition(i)).folderid);
                                //reload list with id
                                mReleaseList.loadList();
                                filter.collapseActionView();
                            }

                            @Override
                            public void onNothingSelected(AdapterView<?> adapterView) {
                                //filter.collapseActionView();
                            }
                        });
                    }
                }
            });
        }

        //make sure only one actionview is expanded
        MenuItemCompat.setOnActionExpandListener(filter, new MenuItemCompat.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionExpand(MenuItem menuItem) {
                //collapse search
                search.collapseActionView();
                return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                return true;
            }
        });
        MenuItemCompat.setOnActionExpandListener(search, new MenuItemCompat.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionExpand(MenuItem menuItem) {
                //collapse search
                filter.collapseActionView();
                return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                return true;
            }
        });

        //s.setSelection(mSearchType,false);

        if (mSelected > 0) {
            if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("enable_lastfm", true)) {
                inflater.inflate(R.menu.release_detail_scrobble, menu);
            }
        }
    }
    return true;
}

From source file:com.cuddlesoft.nori.fragment.EditAPISettingDialogFragment.java

@Override
public void onItemClick(AdapterView<?> listView, View view, int position, long itemId) {
    // This gets called when the user selects a service name autosuggestion.
    // If a known service name was selected, the uri can be auto-completed too.
    String name = (String) listView.getItemAtPosition(position);
    String[] serviceNames = getResources().getStringArray(R.array.service_suggestions_names);
    String[] serviceUris = getResources().getStringArray(R.array.service_suggestions_uris);

    for (int i = 0; i < serviceNames.length; i++) {
        if (serviceNames[i].equals(name)) {
            uri.setText(serviceUris[i]);
        }//from   w w  w .  ja  v a 2s  . c  o  m
    }
}

From source file:com.granita.tasks.QuickAddDialogFragment.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    Cursor c = (Cursor) parent.getItemAtPosition(position);
    mLastColor = TaskFieldAdapters.LIST_COLOR.get(c);
    mColorBackground.setBackgroundColor(mLastColor);
    mSelectedListId = id;//from  w w w  . j  a v  a  2 s  .c  o m
}

From source file:edu.gatech.architourists.VMActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vm);
    datasource = new ArchitectureDataSource(this);
    datasource.open();//  ww  w .  j  a  v a 2 s .  c  o  m
    allArchList = datasource.getAllArchitectures();
    allSiteNames = datasource.getSiteList();

    search = (TextView) findViewById(R.id.search);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            allSiteNames);
    mSearchText = (AutoCompleteTextView) findViewById(R.id.edit_search);
    mSearchText.setAdapter(adapter);
    mSearchText.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String site = (String) parent.getItemAtPosition(position);
            Architecture a = datasource.getArchitecture(site);
            CameraPosition cameraPosition = new CameraPosition(new LatLng(a.getLatitude(), a.getLongitude()),
                    15, 0, 0);
            mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
            mSearchText.clearFocus();
            //
        }

    });
    mSearchText.setOnFocusChangeListener(new OnFocusChangeListener() {
        InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!(hasFocus)) {
                mgr.hideSoftInputFromWindow(mSearchText.getWindowToken(), 0);
            }
        }

    });
    setUpMapIfNeeded();
}