List of usage examples for android.widget AdapterView getItemAtPosition
public Object getItemAtPosition(int position)
From source file:org.krackedeggs.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); //adapter init with null cursor, loader will later fill this View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forcast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w ww . j a va 2 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()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.shearosario.tothepathandback.ClosestStationsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_closest_stations); getActionBar().setDisplayHomeAsUpEnabled(true); Intent intent = getIntent();/* w ww.j a v a 2s . c om*/ context = this; activity = this; adView = (AdView) this.findViewById(R.id.adViewClosest); AdRequest adRequest = new AdRequest.Builder().addTestDevice("949F5429A9EC251C1DD4395558D33531").build(); // AdRequest adRequest = new AdRequest.Builder().build(); adView.loadAd(adRequest); if (intent.hasExtra("Manual")) { double[] manual = intent.getDoubleArrayExtra("Manual"); origin = new LatLng(manual[0], manual[1]); } else if (intent.hasExtra("Current")) { double[] current = intent.getDoubleArrayExtra("Current"); origin = new LatLng(current[0], current[1]); } double[] entranceMeasures = intent.getDoubleArrayExtra("closestSortMeasures"); ArrayList<Entrance> closestEntrances = intent.getParcelableArrayListExtra("closestEntrances"); MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(this, R.layout.listitem, closestEntrances, entranceMeasures); //ListAdapter adapter = createListAdapter(allStationsSortDistance); ListView listview = (ListView) findViewById(R.id.ClosestStationsList); listview.setAdapter(adapter); //setListAdapter(adapter); final GoogleMap gMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.mapview)).getMap(); gMap.setMyLocationEnabled(false); gMap.addMarker(new MarkerOptions().title("Origin").position(origin)); gMap.moveCamera(CameraUpdateFactory.newLatLngZoom(origin, 13)); gMap.setBuildingsEnabled(false); gMap.getUiSettings().setZoomControlsEnabled(false); TextView textView = (TextView) findViewById(R.id.osm_directions); textView.setText(Html.fromHtml("Data provided by OpenStreetMap contributors " + "<a href=\"http://www.openstreetmap.org/copyright\">License</a>")); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView = (TextView) findViewById(R.id.directions_text); textView.setText(Html.fromHtml( "Directions, Nominatim Search Courtesy of " + "<a href=\"http://www.mapquest.com\">MapQuest</a>")); textView.setMovementMethod(LinkMovementMethod.getInstance()); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Entrance item = (Entrance) parent.getItemAtPosition(position); gMap.clear(); LatLngBounds bounds = new LatLngBounds.Builder().include(origin) .include(new LatLng(item.getEntranceLocation()[0], item.getEntranceLocation()[1])).build(); gMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 150)); gMap.addMarker(new MarkerOptions().title("Origin").position(origin)); String stationName = null; for (int i = 0; i < MainActivity.getAllStations().size(); i++) { if (item.getStopid().equalsIgnoreCase(MainActivity.getAllStations().get(i).getStopID())) { stationName = MainActivity.getAllStations().get(i).getStopName(); break; } } gMap.addMarker(new MarkerOptions() // .title(item.getStationName()) .title(stationName) .position(new LatLng(item.getEntranceLocation()[0], item.getEntranceLocation()[1]))); Button button = (Button) findViewById(R.id.button_destination); button.setEnabled(true); // button.setText("Select " + item.getStationName()); button.setText("Select " + stationName); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { /* * To check if the phone is currently using a network connection. * Listens to broadcasts when the the device is or is not connected to * a network */ ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (!isConnected) { Toast.makeText(context, "No network connection", Toast.LENGTH_SHORT).show(); return; } new DisplayDirectionsIntent(context, activity, origin, item); } }); } }); }
From source file:jp.co.conit.sss.sp.ex1.fragment.MybooksListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mSelfActibity = getActivity();//from www .jav a2s . c o m if (savedInstanceState != null) { mIsRemoveMode = savedInstanceState.getBoolean("remove_mode"); } setEmptyText(getString(R.string.empty_purchase_book_data)); mMyBookAdapter = new MyBookAdapter(mSelfActibity, null, true); setListAdapter(mMyBookAdapter); getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Cursor c = (Cursor) parent.getItemAtPosition(position); String productId = c.getString(1); boolean isFree = (c.getInt(5) == 0) ? true : false; Builder builder = new Book.Builder(productId); Book book = builder.build(); if (mIsRemoveMode) { PurchasedBookDao purchasedBookDao = new PurchasedBookDao(mSelfActibity); boolean isSuccessDeleteBookData = purchasedBookDao.deleteData(productId); boolean isSuccessDeleteBookReceipt = false; if (isFree) { // ?????????? isSuccessDeleteBookReceipt = true; } else { PurchaseDatabase purchaseDatabase = new PurchaseDatabase(mSelfActibity); isSuccessDeleteBookReceipt = purchaseDatabase.delete(productId); } File file = new File(FileUtil.generateBookFilePath(mSelfActibity, book)); if (file.exists()) { file.delete(); } if (isSuccessDeleteBookData && isSuccessDeleteBookReceipt) { Toast.makeText(mSelfActibity, getString(R.string.delete_purchase_book_data), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(mSelfActibity, getString(R.string.delete_purchase_book_data_fail), Toast.LENGTH_SHORT).show(); } c.requery(); } else { mOnMypageItemSelectedListener.onMypageItemSelected(book); } } }); mPurchasedBookDao = new PurchasedBookDao(mSelfActibity); getMybooksListAsync(); }
From source file:com.chriscartland.octaviastreethilton.ui.MainActivity.java
private void createTransactionViews() { mTransactions = new ArrayList<>(); mListView = (ListView) findViewById(R.id.transaction_list); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w .j av a2 s. co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.d(TAG, "Transaction clicked: " + position); Log.d(TAG, "UIDEBTS transaction before intent=" + parent.getItemAtPosition(position)); Intent intent = new Intent(MainActivity.this, TransactionActivity.class); intent.putExtra(Transaction.EXTRA, (Transaction) parent.getItemAtPosition(position)); startActivity(intent); } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.attachToListView(mListView); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "TODO(cartland): Launch activity to create transaction"); Firebase newItem = mFirebase.child("transactions").push(); Transaction newTransaction = new Transaction(); newTransaction.setId(newItem.getKey()); Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); String date = String.format("%04d-%02d-%02d", year, month + 1, day); newTransaction.setDate(date); newItem.setValue(newTransaction); Intent intent = new Intent(MainActivity.this, TransactionActivity.class); intent.putExtra(Transaction.EXTRA, newTransaction); startActivity(intent); } }); }
From source file:com.justinbull.ichnaeachecker.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w ww.j a v a 2 s . c o m setCellInfo(); mCellListView = (ListView) findViewById(R.id.cellListView); mCellListView.setAdapter(mCellListAdapter); mCellListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mCellListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { GeneralCellInfo cell = (GeneralCellInfo) parent.getItemAtPosition(position); if (!cell.isFullyKnown()) { Snackbar snack = Snackbar.make(view, "Not enough information known about selected cell", Snackbar.LENGTH_SHORT); snack.getView() .setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.colorError)); snack.show(); return; } mSelectedCell = cell; view.setSelected(true); Snackbar.make(view, "Selected " + mSelectedCell.getCellType() + " Cell " + mSelectedCell.getFriendlyCellIdentity(), Snackbar.LENGTH_SHORT).show(); } }); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); assert fab != null; fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { if (ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) { setCellInfo(); } if (mSelectedCell == null) { Toast.makeText(MainActivity.this, "Choose a cell to check", Toast.LENGTH_SHORT).show(); return; } final Snackbar snack = Snackbar.make(view, "Checking Mozilla Location Services database...", Snackbar.LENGTH_INDEFINITE); snack.show(); try { final RequestHandle handler = getIchnaeaLookup(snack); assert handler != null; snack.setAction("CANCEL", new View.OnClickListener() { @Override public void onClick(View view) { snack.setText("Cancelling lookup request..."); if (!handler.isFinished()) { handler.cancel(true); } else { snack.setText("Request already finished!"); snack.setDuration(Snackbar.LENGTH_LONG); snack.show(); } } }).show(); } catch (IllegalArgumentException e) { Log.w(TAG, "onClick: ", e); snack.setDuration(Snackbar.LENGTH_SHORT); snack.setText("Not enough information known about selected cell"); snack.show(); } } }); }
From source file:net.palacesoft.cngstation.client.StationActivity.java
private void initSearchForm() { countries = (Spinner) findViewById(R.id.countries); countries.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*from www .j a v a 2 s . com*/ public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) { String country = adapterView.getItemAtPosition(pos).toString(); new CityLoader(StationActivity.this, country).execute(CITIES_URL); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); cities = (Spinner) findViewById(R.id.cities); Button btnSubmit = (Button) findViewById(R.id.btnSubmit); btnSubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Object selection = cities.getSelectedItem(); if (selection != null && hasText(selection.toString())) { String city = selection.toString(); try { Address address = lookupAddressFromLocationName(city, countries.getSelectedItem().toString()); new StationLoader(StationActivity.this, address, getZoomLevel(), STATIONS_URL).execute(); } catch (Exception e) { showInfoMessage("Problem finding CNG stations for chosen location"); } } } }); }
From source file:com.sayo.android.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Now that we have some dummy forecast data, create an ArrayAdapter. // The ArrayAdapter will take data from a source (like our dummy forecast) and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forcast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. new ArrayList<String>()); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w w w . j a v a2s .co m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String forecast = (String) parent.getItemAtPosition(position); Intent otherIntent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, forecast); startActivity(otherIntent); } }); return rootView; }
From source file:fr.simon.marquis.secretcodes.ui.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); getSupportActionBar().setTitle(Utils.applyCustomTypeFace(getString(R.string.app_name), this)); setContentView(R.layout.activity_main); mEmptyView = findViewById(R.id.emptyView); mGridView = (GridView) findViewById(R.id.gridView); mGridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL); mGridView.setAdapter(new SecretCodeAdapter(this, Utils.getSecretCodes(this))); mGridView.setEmptyView(mEmptyView);/*from w ww .j a va2 s. c om*/ mEmptyView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mEmptyView.setEnabled(false); mEmptyView.animate().alpha(0) .setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); startService(new Intent(MainActivity.this, CrawlerService.class)); } }); mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { String code = ((SecretCode) arg0.getItemAtPosition(arg2)).getCode(); Toast.makeText(MainActivity.this, getString(R.string.execute_code, code), Toast.LENGTH_SHORT) .show(); try { sendBroadcast(new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_secret_code://" + code))); } catch (java.lang.SecurityException se) { Toast.makeText(MainActivity.this, R.string.security_exception, Toast.LENGTH_LONG).show(); } } }); mGridView.setMultiChoiceModeListener(new MultiChoiceModeListener() { @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { ((SecretCodeAdapter) mGridView.getAdapter()).itemCheckedStateChanged(position, checked); mode.setTitle(Html.fromHtml("<b>" + mGridView.getCheckedItemCount() + "</b>")); } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: ((SecretCodeAdapter) mGridView.getAdapter()).deleteSelection(getApplicationContext()); mode.finish(); return true; case R.id.action_select_all: boolean check = mGridView.getCheckedItemCount() != mGridView.getCount(); for (int i = 0; i < mGridView.getCount(); i++) { mGridView.setItemChecked(i, check); } return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); if (inflater != null) { inflater.inflate(R.menu.cab, menu); } return true; } @Override public void onDestroyActionMode(ActionMode mode) { ((SecretCodeAdapter) mGridView.getAdapter()).resetSelection(); supportInvalidateOptionsMenu(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } }); supportInvalidateOptionsMenu(); }
From source file:com.runnable.weather.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 MainWeatherActivity mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/* w ww. j ava 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(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:net.ustyugov.jtalk.activity.muc.Bookmarks.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); service = JTalkService.getInstance(); setTheme(Colors.isLight ? R.style.AppThemeLight : R.style.AppThemeDark); setTitle(R.string.Bookmarks);//from ww w . j a va2 s . c o m getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.paged_activity); LinearLayout linear = (LinearLayout) findViewById(R.id.linear); linear.setBackgroundColor(Colors.BACKGROUND); LayoutInflater inflater = LayoutInflater.from(this); MainPageAdapter adapter = new MainPageAdapter(mPages); Cursor cursor = service.getContentResolver().query(JTalkProvider.ACCOUNT_URI, null, AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); do { final String account = cursor.getString(cursor.getColumnIndex(AccountDbHelper.JID)).trim(); View bookPage = inflater.inflate(R.layout.list_activity, null); bookPage.setTag(account); mPages.add(bookPage); ListView list = (ListView) bookPage.findViewById(R.id.list); list.setDividerHeight(0); list.setCacheColorHint(0x00000000); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { RosterItem item = (RosterItem) parent.getItemAtPosition(position); BookmarkedConference bc = (BookmarkedConference) item.getObject(); String account = item.getAccount(); String jid = bc.getJid(); String pass = bc.getPassword(); String nick = service.getDerivedNick(service.getConnection(account).getUser(), bc); if (!service.getJoinedConferences().containsKey(jid)) { Toast.makeText(Bookmarks.this, "Attempt joining to " + jid, Toast.LENGTH_SHORT).show(); service.joinRoom(account, jid, nick, pass); } } }); list.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) { final RosterItem item = (RosterItem) parent.getItemAtPosition(position); CharSequence[] items = new CharSequence[3]; items[0] = getString(R.string.Users); items[1] = getString(R.string.Edit); items[2] = getString(R.string.Remove); AlertDialog.Builder builder = new AlertDialog.Builder(Bookmarks.this); builder.setTitle(R.string.Actions); builder.setItems(items, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: MucDialogs.showUsersDialog(Bookmarks.this, account, (BookmarkedConference) item.getObject()); break; case 1: BookmarksDialogs.EditDialog(Bookmarks.this, account, (BookmarkedConference) item.getObject()); break; case 2: try { BookmarkedConference bc = (BookmarkedConference) item.getObject(); BookmarkManager bm = BookmarkManager .getBookmarkManager(service.getConnection(account)); bm.removeBookmarkedConference(bc.getJid()); } catch (Exception e) { Log.e("Remove", e.getLocalizedMessage()); } updateBookmarks(); break; } } }); builder.create().show(); return true; } }); } while (cursor.moveToNext()); cursor.close(); } mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(adapter); mPager.setCurrentItem(0); TitlePageIndicator mTitleIndicator = (TitlePageIndicator) findViewById(R.id.indicator); mTitleIndicator.setTextColor(0xFF555555); mTitleIndicator.setViewPager(mPager); }