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.wart.magister.SelectSchoolActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select_school); // Display the Actionbar arrow getActionBar().setDisplayHomeAsUpEnabled(false); ((EditText) findViewById(R.id.select_school_edittext)).addTextChangedListener(new TextWatcher() { @Override//from www.j a v a 2 s. c om public void afterTextChanged(Editable e) { if (e.length() > 0) { showProgress(true); if (mRetrieveSchoolsRequest != null && !mRetrieveSchoolsRequest.isFinished()) mRetrieveSchoolsRequest.cancel(true); mRetrieveSchoolsRequest = Global.AsyncHttpClient.get( "http://app.schoolmaster.nl/schoolLicentieService.asmx/Search?term=" + e.toString().replace(" ", "%20").toLowerCase().trim(), new TextHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, String responseBody) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); mRetrievedSchools.clear(); DefaultHandler handler = new DefaultHandler() { private String currentValue; private School currentSchool; @Override public void characters(char ch[], int start, int length) throws SAXException { currentValue = new String(ch, start, length); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equalsIgnoreCase("medius")) currentSchool.URL = currentValue; else if (qName.equalsIgnoreCase("licentie")) currentSchool.License = currentValue; } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase("school")) { currentSchool = new School(); mRetrievedSchools.add(currentSchool); } } }; saxParser.parse(new InputSource(new StringReader(responseBody)), handler); String[] names = new String[mRetrievedSchools.size()]; for (int i = 0; i < mRetrievedSchools.size(); i++) names[i] = mRetrievedSchools.get(i).License; mSchoolsList.setAdapter(new ArrayAdapter<String>(SelectSchoolActivity.this, android.R.layout.simple_list_item_1, names)); } catch (Exception e) { Log.e(TAG, "Error in onSuccess", e); } } @Override public void onFailure(String responseBody, Throwable error) { mSchoolsList.setAdapter(null); Log.e(TAG, "Retrieving schools failed", error); } @Override public void onFinish() { showProgress(false); } }); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mSchoolsList = (ListView) findViewById(R.id.select_school_listview); mSchoolsList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mTestMediusRequest != null && !mTestMediusRequest.isFinished()) mTestMediusRequest.cancel(true); ((TextView) findViewById(R.id.select_school_status_message)).setText("Testing school..."); showProgress(true); Data.set(Data.MEDIUSURL, Data.buildMediusUrl(mRetrievedSchools.get(position).URL)); Log.v(TAG, "posting to " + Data.getString(Data.MEDIUSURL)); byte[] request = new byte[54]; request[0] = 0x52; request[1] = 0x4f; request[2] = 49; request[3] = 48; request[4] = 55; request[12] = 95; request[13] = -38; request[14] = -109; request[15] = 13; request[16] = -14; request[17] = 92; request[18] = 7; request[19] = 86; request[20] = -77; request[21] = -23; request[22] = 9; request[23] = 22; request[24] = 71; request[25] = -53; request[26] = -81; request[27] = 45; request[28] = 5; request[32] = 76; request[33] = 111; request[34] = 103; request[35] = 105; request[36] = 110; request[37] = 13; request[41] = 71; request[42] = 101; request[43] = 116; request[44] = 83; request[45] = 99; request[46] = 104; request[47] = 111; request[48] = 111; request[49] = 108; request[50] = 78; request[51] = 97; request[52] = 109; request[53] = 101; Log.i(TAG, "Testing the url..."); mTestMediusRequest = Global.AsyncHttpClient.post(SelectSchoolActivity.this, Data.getString(Data.MEDIUSURL), new ByteArrayEntity(request), "text/html", new BinaryHttpResponseHandler(new String[] { "text/html" }) { @Override public void onSuccess(byte[] binaryData) { if (binaryData != null) { Log.i(TAG, "Received " + binaryData.length + " bytes of data"); Serializer s = new Serializer(binaryData); try { if (s.readROHeader(null, "login", "getschoolname")) { Data.set(Data.LICENSE, s.readString()); MediusCall.setLicense(Data.getString(Data.LICENSE)); } else Log.e(TAG, "Geblokkeerd door webserver"); } catch (Exception e) { Log.e(TAG, "Error in TestMedius.onSuccess", e); } Log.i(TAG, "Succesfully tested the medius"); SelectSchoolActivity.this.startActivity( new Intent(SelectSchoolActivity.this, LoginActivity.class)); } else Log.e(TAG, "TestMedius timed out"); } @Override public void onFailure(int statusCode, Header[] headers, byte[] binaryData, Throwable error) { Log.e(TAG, "Error in TestMedius.onFaillure", error); } @Override public void onFinish() { showProgress(false); } }); } }); mSearchLayout = (LinearLayout) findViewById(R.id.select_school_status_layout); }
From source file:at.bitfire.davdroid.ui.CreateCalendarActivity.java
@Override public void onLoadFinished(Loader<AccountInfo> loader, AccountInfo info) { Spinner spinner = (Spinner) findViewById(R.id.time_zone); String[] timeZones = TimeZone.getAvailableIDs(); spinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, timeZones)); // select system time zone String defaultTimeZone = TimeZone.getDefault().getID(); for (int i = 0; i < timeZones.length; i++) if (timeZones[i].equals(defaultTimeZone)) { spinner.setSelection(i);//from w ww . jav a 2 s .c o m break; } if (info != null) { spinner = (Spinner) findViewById(R.id.home_sets); spinner.setAdapter( new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, info.homeSets)); } }
From source file:de.golov.zeitgeistreich.ZeitGeistReichActivity.java
/** Called when the activity is first created. */ @Override/*from www.j a v a 2s .c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final ImageView imagePreview = (ImageView) findViewById(R.id.ImagePreview); Intent intent = getIntent(); Bundle extras = intent.getExtras(); Uri mImageUri = null; if (Intent.ACTION_SEND.equals(intent.getAction()) && extras != null) { if (extras.containsKey(Intent.EXTRA_STREAM)) { mImageUri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM); if (mImageUri != null) { int origId = Integer.parseInt(mImageUri.getLastPathSegment()); Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), origId, MediaStore.Images.Thumbnails.MINI_KIND, (BitmapFactory.Options) null); imagePreview.setImageBitmap(bitmap); } } } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, tag_suggests); final MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.TagEditView); textView.setAdapter(adapter); textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); final Button button = (Button) findViewById(R.id.ZeitgeistSubmit); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { submitImage(textView.getText().toString()); } }); }
From source file:com.myandroidremote.AccountsActivity.java
/** * Sets up the 'connect' screen content. *//*from ww w. j av a 2 s . co m*/ private void setConnectScreenContent() { List<String> accounts = getGoogleAccounts(); if (accounts.size() == 0) { // Show a dialog and invoke the "Add Account" activity if requested AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(R.string.needs_account); builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT)); } }); builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { showLoadingScreen(); } }); builder.setIcon(android.R.drawable.stat_sys_warning); builder.setTitle(R.string.attention); builder.show(); } else { final ListView listView = (ListView) findViewById(R.id.select_account); listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); listView.setItemChecked(mAccountSelectedPosition, true); final Button connectButton = (Button) findViewById(R.id.connect); connectButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Register in the background and terminate the activity mAccountSelectedPosition = listView.getCheckedItemPosition(); TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition); register((String) account.getText()); // show connecting showLoadingScreen(); } }); final Button exitButton = (Button) findViewById(R.id.exit); exitButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { finish(); } }); } }
From source file:in.animeshpathak.nextbus.NextBusMain.java
/** Called when the activity is first started. */ @Override// w w w .j ava 2 s .co m public void onCreate(Bundle bundle) { Log.d(LOG_TAG, "entering onCreate()"); SettingsActivity.setTheme(this); super.onCreate(bundle); setContentView(R.layout.main); try { busNet = BusNetwork.getInstance(this); } catch (Exception e) { Log.e(LOG_TAG, e.getMessage(), e); return; } // get the button // set handler to launch a processing dialog ImageButton updateButton = (ImageButton) findViewById(R.id.update_button); updateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { BusLine selectedLine = lineAdapter.getItem(lineSpinner.getSelectedItemPosition()); BusStop selectedStop = stopAdapter.getItem(stopSpinner.getSelectedItemPosition()); getBusTimings(selectedLine, selectedStop); } }); ImageButton feedbackButton = (ImageButton) findViewById(R.id.feedback_button); feedbackButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("message/rfc822"); // use from live device i.putExtra(Intent.EXTRA_EMAIL, new String[] { Constants.FEEDBACK_EMAIL_ADDRESS }); i.putExtra(Intent.EXTRA_SUBJECT, Constants.FEEDBACK_EMAIL_SUBJECT); i.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_hello)); startActivity(Intent.createChooser(i, getString(R.string.select_email_app))); } }); ImageButton phebusinfoButton = (ImageButton) findViewById(R.id.phebusinfo_button); phebusinfoButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog alertDialog = new AlertDialog.Builder(NextBusMain.this).create(); WebView wv = new WebView(NextBusMain.this); new PhebusNewsLoader(wv, NextBusMain.this).execute(); alertDialog.setView(wv); alertDialog.show(); } }); lineSpinner = (Spinner) findViewById(R.id.line_spinner); lineAdapter = new ArrayAdapter<BusLine>(this, android.R.layout.simple_spinner_item, busNet.getLines()); lineAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); lineSpinner.setAdapter(lineAdapter); stopSpinner = (Spinner) findViewById(R.id.stop_spinner); stopAdapter = new ArrayAdapter<BusStop>(this, android.R.layout.simple_spinner_item); stopAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); stopSpinner.setAdapter(stopAdapter); ImageButton favoriteButton = (ImageButton) findViewById(R.id.favorites_button); favoriteButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { new FavoriteDialog(NextBusMain.this, new OnFavoriteSelectedListener() { @Override public void favoriteSelected(Favorite fav) { BusLine bl = busNet.getLineByName(fav.getLine()); BusStop bs = bl.getFirstStopWithSimilarName(fav.getStop()); if (bl == null || bs == null) { Log.e(LOG_TAG, "Favorite not found!"); return; } updateSpinners(bl, bs); getBusTimings(bl, bs); } }, lineSpinner.getSelectedItem().toString(), stopSpinner.getSelectedItem().toString()); } }); }
From source file:com.nextgis.maplibui.formcontrol.AutoTextEdit.java
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences) throws JSONException { ControlHelper.setClearAction(this); JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = ControlHelper.isSaveLastValue(attributes); mAllowSaveNewValue = attributes.optBoolean(JSON_ALLOW_NEW_VALUES); if (!ControlHelper.isEnabled(fields, mFieldName)) { setEnabled(false);// ww w .j a v a2 s . co m setTextColor(Color.GRAY); } String lastValue = null; if (ControlHelper.hasKey(savedState, mFieldName)) lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName)); else if (null != featureCursor) { int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) lastValue = featureCursor.getString(column); } else if (mIsShowLast) lastValue = preferences.getString(mFieldName, null); mAliasValueMap = new HashMap<>(); if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) { MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); if (null == map) throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited"); String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME); long id = attributes.getLong(JSON_NGW_ID_KEY); for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i) instanceof NGWLookupTable) { NGWLookupTable table = (NGWLookupTable) map.getLayer(i); if (table.getRemoteId() != id || !table.getAccountName().equals(account)) continue; for (Map.Entry<String, String> entry : table.getData().entrySet()) { mAliasValueMap.put(entry.getValue(), entry.getKey()); if (entry.getKey().equals(lastValue)) lastValue = entry.getValue(); } break; } } } else { JSONArray values = attributes.getJSONArray(JSON_VALUES_KEY); for (int j = 0; j < values.length(); j++) { JSONObject keyValue = values.getJSONObject(j); String value = keyValue.getString(JSON_VALUE_NAME_KEY); String alias = keyValue.getString(JSON_VALUE_ALIAS_KEY); mAliasValueMap.put(alias, value); if (value.equals(lastValue)) lastValue = alias; } } setText(lastValue); mAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, new ArrayList<>(mAliasValueMap.keySet())); setAdapter(mAdapter); setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus && getText().length() == 0) { postDelayed(new Runnable() { @Override public void run() { showDropDown(); } }, 100); } } }); addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { if (charSequence.length() < 1) getOnFocusChangeListener().onFocusChange(AutoTextEdit.this, true); } @Override public void afterTextChanged(Editable editable) { } }); }
From source file:ack.me.truconnectandroiddemo.MainActivity.java
private void initDeviceList() { ListView deviceListView = (ListView) findViewById(R.id.listView); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listitem, R.id.textView); initialiseListviewListener(deviceListView); mDeviceList = new DeviceList(adapter, deviceListView); }
From source file:com.philips.castdemo.videobrowser.VideoBrowser.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); boolean result = VideoCastManager.checkGooglePlayServices(this); setContentView(R.layout.activity_video_browser); ActionBar actionBar = getSupportActionBar(); mCastManager = CastApplication.getCastManager(this); // -- Adding MiniController mMini = (MiniController) findViewById(R.id.miniController1); mCastManager.addMiniController(mMini); mCastConsumer = new VideoCastConsumerImpl() { @Override/*from w ww .j av a2 s . com*/ public void onFailed(int resourceId, int statusCode) { } @Override public void onConnectionSuspended(int cause) { Log.d(TAG, "onConnectionSuspended() was called with cause: " + cause); com.philips.castdemo.videobrowser.utils.Utils.showToast(VideoBrowser.this, R.string.play); } @Override public void onConnectivityRecovered() { com.philips.castdemo.videobrowser.utils.Utils.showToast(VideoBrowser.this, R.string.connection_recovered); } @Override public void onCastDeviceDetected(final RouteInfo info) { if (!CastPreference.isFtuShown(VideoBrowser.this)) { CastPreference.setFtuShown(VideoBrowser.this); Log.d(TAG, "Route is visible: " + info); new Handler().postDelayed(new Runnable() { @Override public void run() { if (mediaRouteMenuItem.isVisible()) { Log.d(TAG, "Cast Icon is visible: " + info.getName()); showFtu(); } } }, 1000); } } }; setupActionBar(actionBar); mCastManager.reconnectSessionIfPossible(this, false); videopath = (EditText) findViewById(R.id.video_path); videolink = (Spinner) findViewById(R.id.video_link); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, VIDEO_URL); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); videolink.setAdapter(adapter); videolink.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { item_selected = arg2; if (VIDEO_URL[item_selected] != null) { mPath = VIDEO_URL[item_selected]; } videopath.setText(mPath.toCharArray(), 0, mPath.length()); } public void onNothingSelected(AdapterView<?> arg0) { } }); videolink.setVisibility(View.VISIBLE); }
From source file:com.orbar.pxdemo.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = mDrawerTitle = getTitle();/*from w w w.j a va 2s. com*/ // Load the drawer views mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerCategoryList = (ListView) findViewById(R.id.category_list); mDrawerView = (View) findViewById(R.id.left_drawer); // Load account and logout textviews (buttons) mMyAccountViewFlipper = (ViewFlipper) findViewById(R.id.my_account_flipper); mAccountUserName = (TextView) findViewById(R.id.account_header_user_name); mAccountUserIcon = (ImageView) findViewById(R.id.account_header_user_icon); mAccountUserBackground = (ImageView) findViewById(R.id.account_header_background); Log.d(TAG, "mMyAccountViewFlipper is null? " + Boolean.toString(mMyAccountViewFlipper == null)); mLogoutButton = (ImageButton) findViewById(R.id.account_header_logout); // 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 mDrawerCategoryList .setAdapter(new ArrayAdapter<Category>(this, R.layout.drawer_list_item, Category.values())); // setup the open close listener for the drawer mDrawerCategoryList.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); // select the first category (All) if so saved category (ie if orientation changes) if (savedInstanceState == null) { selectItem(0); } // Make the refresh scroll distance to 20% of the GridView height PullToRefreshAttacher.Options ptrOptions = new PullToRefreshAttacher.Options(); ptrOptions.refreshScrollDistance = 0.2f; // get a PullToRefreshAttacher instance mPullToRefreshAttacher = PullToRefreshAttacher.get(this, ptrOptions); // Get the login manager mLoginManager = LoginManager.getInstance(this); // if not logged in, attempt to login (background), otherwise, start the login actions if (!mLoginManager.isLoggedIn()) { mLoginManager.login(); } else { onSuccessLogin(); } // if clicked on my account, open my account page if logged in, other wise go to login page mMyAccountViewFlipper.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mLoginManager.isLoggedIn()) { openMyAccount(); } else { gotoMyAccount = true; gotoLogin(); } } }); // Logout mLogoutButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { logout(); } }); }
From source file:club.frickel.feelathome.DeviceFragment.java
public void updateEffectsFragment(ArrayList<Effect> effects) { // We need to use a different list item layout for devices older than Honeycomb int layout = android.R.layout.simple_list_item_activated_1; // Create an array adapter for the list view, using the Ipsum headlines array setListAdapter(new ArrayAdapter<>(getActivity(), layout, effects)); }