List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects)
From source file:com.alexskyy.gplusauthtest.MainActivity.java
@Override protected void onStart() { super.onStart(); // Button listeners revoke_access_button.setOnClickListener(clicker); sign_out_button.setOnClickListener(clicker); sign_in_button.setOnClickListener(clicker); // CheckBox listeners ((CheckBox) findViewById(R.id.request_auth_code_checkbox)).setOnCheckedChangeListener(this); ((CheckBox) findViewById(R.id.has_token_checkbox)).setOnCheckedChangeListener(this); mCirclesList = new ArrayList<String>(); mCirclesAdapter = new ArrayAdapter<String>(this, R.layout.circle_member, mCirclesList); circles_list.setAdapter(mCirclesAdapter); mGoogleApiClient = buildGoogleApiClient(); mGoogleApiClient.connect();/* ww w. j a v a2 s .c o m*/ }
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityJourney.java
/** * sends a message to the driver of a journey *//*from ww w .java 2 s. c om*/ private void sendMessageToDriver() { final Dialog customDialog = new Dialog(this); customDialog.setContentView(R.layout.custom_dialog_layout); customDialog.setTitle("Message"); final List<String> spinnerArray = new ArrayList<String>(); spinnerArray.add("Everyone"); if (!getApp().getSelectedJourney().getDriver().equals(getApp().getUser())) { spinnerArray.add(getApp().getSelectedJourney().getDriver().getFullName()); } for (int i = 0; i < getApp().getSelectedJourney().getHitchhikers().size(); i++) { if (!getApp().getSelectedJourney().getHitchhikers().get(i).equals(getApp().getUser())) { spinnerArray.add(getApp().getSelectedJourney().getHitchhikers().get(i).getFullName()); } } final Spinner spinner = (Spinner) customDialog.findViewById(R.id.spinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(MapActivityJourney.this, android.R.layout.simple_spinner_item, spinnerArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); ImageView sendBtn = (ImageView) customDialog.findViewById(R.id.sendBtn); final EditText input = (EditText) customDialog.findViewById(R.id.input); sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { User mid = getApp().getUser(); if (spinner.getSelectedItem().toString().equals("Everyone")) { if (input.getText().toString().equals("")) { input.setHint("Please fill in your message"); Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); } else { List<User> userList = new ArrayList<User>(); userList.add(getApp().getSelectedJourney().getDriver()); for (int k = 0; k < getApp().getSelectedJourney().getHitchhikers().size(); k++) { userList.add(getApp().getSelectedJourney().getHitchhikers().get(k)); } userList.remove(getApp().getUser()); for (int k = 0; k < userList.size(); k++) { sendMessage(userList.get(k), input); } Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); customDialog.dismiss(); } } else { for (int j = 0; j < getApp().getSelectedJourney().getHitchhikers().size(); j++) { if (spinner.getSelectedItem().toString() .equals(getApp().getSelectedJourney().getHitchhikers().get(j).getFullName())) { mid = getApp().getSelectedJourney().getHitchhikers().get(j); } } if (spinner.getSelectedItem().toString() .equals(getApp().getSelectedJourney().getDriver().getFullName())) { mid = getApp().getSelectedJourney().getDriver(); } if (input.getText().toString().equals("")) { input.setHint("Please fill in your message"); Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); } else { sendMessage(mid, input); Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); customDialog.dismiss(); } } } }); customDialog.show(); }
From source file:io.github.protino.codewatch.ui.LeaderboardFragment.java
private void createLeaderDialog() { autoCompleteTextView = (AutoCompleteTextView) dialogView.findViewById(R.id.language_autocomplete); autoCompleteTextView.setAdapter(/*from w w w .j av a2s. c o m*/ new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, validLanguages)); validator = new LanguageValidator(getActivity(), autoCompleteTextView, validLanguages); autoCompleteTextView.setValidator(validator); autoCompleteTextView.setOnFocusChangeListener(new FocusListener()); autoCompleteTextView.setThreshold(1); autoCompleteTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { autoCompleteTextView.showDropDown(); } }); filteredCheckbox = (CheckBox) dialogView.findViewById(R.id.filter_rb); filteredCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { autoCompleteTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); }
From source file:org.openplans.rcavl.RCAVL.java
private void switchToLogin() { setContentView(R.layout.login);/*from w w w . j av a 2 s . com*/ SharedPreferences preferences = getPreferences(MODE_PRIVATE); String emails = preferences.getString("emails", ""); String[] past_emails = emails.split(","); if (past_emails == null) { past_emails = new String[0]; } emailField = (AutoCompleteTextView) findViewById(R.id.emailField); passwordField = (TextView) findViewById(R.id.passwordField); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, past_emails); emailField.setAdapter(adapter); spinner = (ProgressBar) findViewById(R.id.loginProgressBar); View loginButton = findViewById(R.id.loginButton); loginButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { spinner.setIndeterminate(true); spinner.setVisibility(View.VISIBLE); new LoginTask().execute(); } }); View configButton = findViewById(R.id.configButton); configButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { ConfigDialog dialog = new ConfigDialog(RCAVL.this); dialog.setConfigured(RCAVL.this); dialog.show(); } }); apiRequestUrl = preferences.getString("apiRequestUrl", apiRequestUrl); pingInterval = preferences.getInt("pingInterval", pingInterval); }
From source file:io.radio.streamer.MainActivity.java
private void initializeSideBar() { // MenuBar/*from ww w . ja va 2 s. c o m*/ mTitle = mDrawerTitle = getTitle(); mDrawerMenu = getResources().getStringArray(R.array.app_menu); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set up the drawer's list view with items and click listener mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mDrawerMenu)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); }
From source file:com.easibeacon.examples.shop.MainActivity.java
@Override public void searchState(final int state) { runOnUiThread(new Runnable() { @Override/*from w ww .j ava 2 s . c o m*/ public void run() { if (state == IBeaconProtocol.SEARCH_STARTED) { _barSearchBeacons.setVisibility(View.VISIBLE); _txtState.setText(R.string.msg_searching_ibeacons); } else if (state == IBeaconProtocol.SEARCH_END_SUCCESS) { _barSearchBeacons.setVisibility(View.GONE); _txtState.setText(""); // Will enter region, probably } else if (state == IBeaconProtocol.SEARCH_END_EMPTY) { _barSearchBeacons.setVisibility(View.GONE); //_txtState.setText(R.string.msg_no_ibeacons_found); //_offers.clear(); //arrayAdapter.notifyDataSetChanged(); // Get the JSON file as a String String json = loadJSONFromAsset(); // create class object gps = new GPSTracker(MainActivity.this); lv = (ListView) findViewById(R.id.listView); // check if GPS enabled if (gps.canGetLocation()) { double latitude = gps.getLatitude(); double longitude = gps.getLongitude(); //Print JSON Object try { List<String> results = new ArrayList<String>(); JSONObject jsonObject = new JSONObject(json); JSONArray jsonArray = jsonObject.getJSONArray("monuments"); Location myPosition = new Location("a"); myPosition.setLatitude(latitude); myPosition.setLongitude(longitude); Location monumentLoc = new Location("b"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject monumentObject = jsonArray.getJSONObject(i); monumentLoc.setLatitude(monumentObject.getDouble("latitude")); monumentLoc.setLongitude(monumentObject.getDouble("longitude")); distance = myPosition.distanceTo(monumentLoc); distance = distance / 1000; distanceR = (double) Math.round(distance * 100.0) / 100.0; results.add(monumentObject.getInt("id") + "." + monumentObject.getString("name") + " " + "(" + distanceR + "km )"); } ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, results); lv.setAdapter(arrayAdapter); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { // TODO: CALL THE MapActivity String itemName = (String) lv.getItemAtPosition(i); Intent map = new Intent(getApplicationContext(), MapsActivity.class); map.putExtra("id", itemName); startActivity(map); } }); } catch (Throwable t) { Log.e("My App", "Could not parse malformed JSON: \"" + json); } } else { // Ask user to enable GPS/network in settings gps.showSettingsAlert(); } } } }); }
From source file:com.justinbull.ichnaeachecker.MainActivity.java
public void setCellInfo() { int tmPermCheck = ContextCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION); if (tmPermCheck == PackageManager.PERMISSION_GRANTED) { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 && tm.getAllCellInfo() != null) { mVisibleCells = GeneralCellInfoFactory.getInstances(tm.getAllCellInfo()); // Sort cells by strength Collections.sort(mVisibleCells, new Comparator<GeneralCellInfo>() { @Override/*from www . j a v a 2 s. c o m*/ public int compare(GeneralCellInfo lhs, GeneralCellInfo rhs) { int lhsDbm = lhs.getAsuStrength(); int rhsDbm = rhs.getAsuStrength(); if (lhsDbm == rhsDbm) { return 0; } return lhsDbm > rhsDbm ? -1 : 1; } }); mRegisteredCells.clear(); if (mVisibleCells.size() == 0) { Log.w(TAG, "setCellInfo: No visible cells (primary or neighbours), unable to do anything"); } for (GeneralCellInfo cell : mVisibleCells) { Log.i(TAG, "Device aware of " + cell.toString()); if (cell.isRegistered()) { mRegisteredCells.add(cell); } } if (mRegisteredCells.isEmpty()) { Log.w(TAG, "setCellInfo: No registered cells, nothing to select."); mSelectedCell = null; } else { Log.i(TAG, "setCellInfo: Preselected strongest registered cell: " + mRegisteredCells.get(0)); mSelectedCell = mRegisteredCells.get(0); } } else { Log.e(TAG, "setCellInfo: Android device too old to use getAllCellInfo(), need to implement getCellLocation() fallback!"); } mCellListAdapter = new ArrayAdapter<GeneralCellInfo>(this, android.R.layout.simple_list_item_1, mVisibleCells); } else if (tmPermCheck == PackageManager.PERMISSION_DENIED) { if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION)) { Toast.makeText(MainActivity.this, "Dude we need permissions", Toast.LENGTH_LONG).show(); } ActivityCompat.requestPermissions(MainActivity.this, new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, Consts.REQUEST_COARSE_LOCATION); } else { Log.wtf(TAG, "setCellInfo: Received unknown int from ContextCompat.checkSelfPermission()"); } }
From source file:nl.mpcjanssen.simpletask.util.Util.java
public static ArrayAdapter<String> newSpinnerAdapter(Context cxt, List<String> items) { ArrayAdapter<String> adapter = new ArrayAdapter<String>(cxt, android.R.layout.simple_spinner_item, items); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); return adapter; }
From source file:in.shick.diode.common.Common.java
/** * Helper function to display a list of URLs. * @param theContext The current application context. * @param settings The settings to use regarding the browser component. * @param theItem The ThingInfo item to get URLs from. *//* w ww .j a va 2 s . co m*/ public static void showLinksDialog(final Context theContext, final RedditSettings settings, final ThingInfo theItem) { assert (theContext != null); assert (theItem != null); assert (settings != null); final ArrayList<String> urls = new ArrayList<String>(); final ArrayList<MarkdownURL> vtUrls = theItem.getUrls(); for (MarkdownURL vtUrl : vtUrls) { urls.add(vtUrl.url); } ArrayAdapter<MarkdownURL> adapter = new ArrayAdapter<MarkdownURL>(theContext, android.R.layout.select_dialog_item, vtUrls) { public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { tv = (TextView) ((LayoutInflater) theContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(android.R.layout.select_dialog_item, null); } else { tv = (TextView) convertView; } String url = getItem(position).url; String anchorText = getItem(position).anchorText; // if (Constants.LOGGING) Log.d(TAG, "links url="+url + " anchorText="+anchorText); Drawable d = null; try { d = theContext.getPackageManager() .getActivityIcon(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } catch (PackageManager.NameNotFoundException ignore) { } if (d != null) { d.setBounds(0, 0, d.getIntrinsicHeight(), d.getIntrinsicHeight()); tv.setCompoundDrawablePadding(10); tv.setCompoundDrawables(d, null, null, null); } final String telPrefix = "tel:"; if (url.startsWith(telPrefix)) { url = PhoneNumberUtils.formatNumber(url.substring(telPrefix.length())); } if (anchorText != null) tv.setText(Html.fromHtml("<span>" + anchorText + "</span><br /><small>" + url + "</small>")); else tv.setText(Html.fromHtml(url)); return tv; } }; AlertDialog.Builder b = new AlertDialog.Builder( new ContextThemeWrapper(theContext, settings.getDialogTheme())); DialogInterface.OnClickListener click = new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { if (which >= 0) { Common.launchBrowser(settings, theContext, urls.get(which), Util.createThreadUri(theItem).toString(), false, false, settings.isUseExternalBrowser(), settings.isSaveHistory()); } } }; b.setTitle(R.string.select_link_title); b.setCancelable(true); b.setAdapter(adapter, click); b.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public final void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); b.show(); }