List of usage examples for android.widget ArrayAdapter getCount
@Override public int getCount()
From source file:de.uni_koblenz_landau.apow.SettingsFragment.java
/** * Called by settings task, when loading is finished. *//*from w w w . j av a2 s .com*/ @Override public void onSettingsFetched(ListViewItem settings, List<ListViewItem> locations) { mSettingsTask = null; // If result is not empty, update UI, else show error message. if (settings != null && locations != null) { mSettings = settings; mUsernameView.setText(mSettings.getField1()); mPasswordView.setText(mSettings.getField2()); mLocations = locations; ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, locations); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLocationsView.setAdapter(adapter); int position = -1; for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).getId() == settings.getId()) { position = i; break; } } mLocationsView.setSelection(position); } else { Toast.makeText(getActivity(), R.string.error_database, Toast.LENGTH_SHORT).show(); } }
From source file:com.sbhstimetable.sbhs_timetable_android.NavigationDrawerFragment.java
public void updateList() { ArrayAdapter<NavBarFancyAdapter.DrawerEntry> a = (ArrayAdapter<NavBarFancyAdapter.DrawerEntry>) mDrawerListView .getAdapter();//from w ww. j a v a 2s . c o m int drawable = (ThemeHelper.isBackgroundDark() ? R.drawable.ic_edit_white_24dp : R.drawable.ic_edit_dark_24dp); if (ApiAccessor.isLoggedIn()) { this.botElements.remove(1); this.botElements.add(new NavBarFancyAdapter.DrawerEntry(drawable, getString(R.string.action_logout), this.getActivity())); } else { if (a.getCount() < 2) { this.botElements.add(new NavBarFancyAdapter.DrawerEntry(drawable, getString(R.string.action_login), this.getActivity())); } } }
From source file:de.uni_koblenz_landau.apow.EncounterDetailFragment.java
/** * Called by EncounterDetailTask, when loading is finished. *//* ww w . j av a 2 s. c o m*/ @Override public void onEncounterFetched(Encounter encounter, List<ListViewItem> types) { mEncounterDetailTask = null; // If result is not empty, update UI, else show error message. if (types != null) { mTypes = types; ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, types); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mTypesView.setAdapter(adapter); if (encounter != null) { mEncounter = encounter; mDateView.setText(Helper.dateToLocaleString(mEncounter.getEncounterDatetime(), getActivity())); mTimeView.setText(Helper.dateToLocaleTimeString(mEncounter.getEncounterDatetime(), getActivity())); int position = -1; for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).getId() == mEncounter.getEncounterType().getEncounterTypeId()) { position = i; break; } } mTypesView.setSelection(position); } else { mEncounter = new Encounter(); mDateView.setText(Helper.dateToLocaleString(new Date(), getActivity())); mTimeView.setText(Helper.dateToLocaleTimeString(new Date(), getActivity())); } } else { Toast.makeText(getActivity(), R.string.error_database, Toast.LENGTH_SHORT).show(); } }
From source file:com.example.google.walkway.MainActivity.java
private void setupNavList() { Log.d(LOG_TAG, "setupNavList()"); mNavListView = (ListView) this.findViewById(R.id.nav_list); ArrayAdapter<String> navAdapter = new NavArrayAdapter<String>(this, R.layout.listview_item); mNavListView.setAdapter(navAdapter); for (PlaceType placeType : NAV_PLACE_TYPES) { navAdapter.add(placeType.name().toLowerCase(Locale.US)); }/*from w ww .j a va 2 s.co m*/ navAdapter.add("div"); // Divider navAdapter.add("about"); // TODO create constants final int aboutIndex = navAdapter.getCount() - 1; // TODO should have a better way mNavListView.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { if (index == aboutIndex) { mDrawerLayout.closeDrawer(mNavListView); Intent intent = new Intent(MainActivity.this, AboutActivity.class); startActivity(intent); } } }); View leftHandle = findViewById(R.id.left_handle); leftHandle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mDrawerLayout.openDrawer(mNavListView); } }); }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * Received custom server from AddServerActivity, add prefix "http://" before it. * Add the result in custom server list and set it as current server. * //from w ww . j a v a2s . c o m * @see android.app.Activity#onActivityResult(int, int, android.content.Intent) */ @SuppressWarnings("unchecked") @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { String result = data.getDataString(); if (Constants.REQUEST_CODE == requestCode && !TextUtils.isEmpty(result)) { if (Constants.RESULT_CONTROLLER_URL == resultCode) { currentServer = "http://" + result; ArrayAdapter<String> customeListAdapter = (ArrayAdapter<String>) customListView.getAdapter(); customeListAdapter.add(currentServer); customListView.setItemChecked(customeListAdapter.getCount() - 1, true); AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); writeCustomServerToFile(); requestPanelList(); checkAuthentication(); requestAccess(); } } } }
From source file:org.uguess.android.sysinfo.NetStateManager.java
void refresh() { ArrayList<ConnectionItem> data = new ArrayList<ConnectionItem>(); data.add(dummyInfo);//from w ww .ja v a2 s. c o m ArrayList<ConnectionItem> items = readStatesRaw(); if (items != null) { final int type = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_ORDER_TYPE, ORDER_TYPE_PROTO); final int direction = Util.getIntOption(getActivity(), PSTORE_NETMANAGER, PREF_KEY_SORT_DIRECTION, ORDER_ASC); final Collator clt = Collator.getInstance(); switch (type) { case ORDER_TYPE_PROTO: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.proto, obj2.proto) * direction; } }); break; case ORDER_TYPE_LOCAL: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.local, obj2.local) * direction; } }); break; case ORDER_TYPE_REMOTE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.remoteName == null ? obj1.remote : obj1.remoteName, obj2.remoteName == null ? obj2.remote : obj2.remoteName) * direction; } }); break; case ORDER_TYPE_STATE: Collections.sort(items, new Comparator<ConnectionItem>() { public int compare(ConnectionItem obj1, ConnectionItem obj2) { return clt.compare(obj1.state == null ? "" //$NON-NLS-1$ : obj1.state, obj2.state == null ? "" //$NON-NLS-1$ : obj2.state) * direction; } }); break; } data.addAll(items); } ArrayAdapter<ConnectionItem> adapter = (ArrayAdapter<ConnectionItem>) getListView().getAdapter(); adapter.setNotifyOnChange(false); adapter.clear(); for (int i = 0, size = data.size(); i < size; i++) { adapter.add(data.get(i)); } adapter.notifyDataSetChanged(); if (adapter.getCount() == 1) { Log.d(NetStateManager.class.getName(), "No network traffic detected"); //$NON-NLS-1$ } }
From source file:org.sufficientlysecure.keychain.ui.dialog.CreateKeyDialogFragment.java
private void setKeyLengthSpinnerValuesForAlgorithm(int algorithmId) { final ArrayAdapter<CharSequence> keySizeAdapter = (ArrayAdapter<CharSequence>) mKeySizeSpinner.getAdapter(); final Object selectedItem = mKeySizeSpinner.getSelectedItem(); keySizeAdapter.clear();//from w w w . j a va 2s. com switch (algorithmId) { case Constants.choice.algorithm.rsa: replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_rsa)); break; case Constants.choice.algorithm.elgamal: replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values); mCustomKeyInfoTextView.setText(""); // ElGamal does not support custom key length break; case Constants.choice.algorithm.dsa: replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_dsa)); break; } keySizeAdapter.notifyDataSetChanged(); // when switching algorithm, try to select same key length as before for (int i = 0; i < keySizeAdapter.getCount(); i++) { if (selectedItem.equals(keySizeAdapter.getItem(i))) { mKeySizeSpinner.setSelection(i); break; } } }
From source file:de.uni_koblenz_landau.apow.ObsDetailFragment.java
/** * Called by settings task, when loading is finished. *//*w ww. j ava2s . c o m*/ @Override public void onObsFetched(Obs obs, List<ListViewItem> testConcepts) { mObsDetailTask = null; // If result is not empty, update UI, else show error message. if (testConcepts != null) { mTestConcepts = testConcepts; ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, mTestConcepts); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mTestConceptView.setAdapter(adapter); if (obs != null) { mObs = obs; // Observation is question. if (mObs.getConcept().getConceptId() == Constants.QUESTION_CONCEPT_ID) { mQuestionTextView.setText(mObs.getValueText()); // Observation is test. } else if (mObs.getConcept().getConceptClass().getConceptClassId() == Constants.TEST_CLASS_ID) { mTestValueView.setText("" + mObs.getValueNumeric()); mTestUnitView.setText(((ConceptNumeric) mObs.getConcept()).getUnits()); int position = -1; for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).getId() == mObs.getConcept().getConceptId()) { position = i; break; } } mTestConceptView.setSelection(position); // Observation is finding. } else if (mObs.getConcept().getConceptId() == Constants.FINDING_SET_CONCEPT_ID) { for (Obs obs1 : mObs.getGroupMembers()) { if (obs1.getConcept().getConceptId() == Constants.FINDING_CONCEPT) { mFindingValueCodedView.setText(obs1.getValueCoded().getName().getName()); findingCode = obs1.getValueCoded().getConceptId(); } if (obs1.getConcept().getConceptId() == Constants.FINDING_CERTAINTY && obs1.getValueCoded().getConceptId() == Constants.FINDING_CERTAINTY_CONFIRMED) { mFindingCertaintyView.setChecked(true); } if (obs1.getConcept().getConceptId() == Constants.FINDING_SEVERITY && obs1.getValueCoded().getConceptId() == Constants.FINDING_SEVERITY_PRIMARY) { mFindingSeverityCodedView.setChecked(true); } } // Observation is symptom. } else if (mObs.getConcept().getConceptClass() .getConceptClassId() == Constants.SYMPTOM_CONCEPT_CLASS_ID) { mSymptomValueView.setText(mObs.getConcept().getName().getName()); symptomCode = mObs.getConcept().getConceptId(); } } else { mObs = new Obs(); mObs.setEncounter(new Encounter(mEncounterID)); } restoreView(); } else { Toast.makeText(getActivity(), R.string.error_database, Toast.LENGTH_SHORT).show(); } }
From source file:com.example.yudiandrean.socioblood.Register.java
/** * Called when the activity is first created. *//*w ww. jav a 2 s .c o m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.register); /** * Defining all layout items **/ inputFirstName = (EditText) findViewById(R.id.firstname); inputLastName = (EditText) findViewById(R.id.lastname); inputUsername = (EditText) findViewById(R.id.username); inputEmail = (EditText) findViewById(R.id.email); inputPassword = (EditText) findViewById(R.id.password); btnRegister = (Button) findViewById(R.id.register); registerErrorMsg = (TextView) findViewById(R.id.register_error); //Blood type spinner inputBloodType = (Spinner) findViewById(R.id.bloodtype_spinner); ArrayAdapter<String> bloodadapter = new ArrayAdapter<String>(Register.this, android.R.layout.simple_spinner_dropdown_item) { @Override public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); if (position == getCount()) { ((TextView) v.findViewById(android.R.id.text1)).setText(""); ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed" } return v; } @Override public int getCount() { return super.getCount() - 1; // you dont display last item. It is used as hint. } }; bloodadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); bloodadapter.add("O"); bloodadapter.add("A"); bloodadapter.add("B"); bloodadapter.add("AB"); bloodadapter.add("Blood Type"); inputBloodType.setAdapter(bloodadapter); inputBloodType.setSelection(bloodadapter.getCount()); //display hint //Rhesus spinner inputRhesus = (Spinner) findViewById(R.id.rhesus_spinner); ArrayAdapter<String> rhesusadapter = new ArrayAdapter<String>(Register.this, android.R.layout.simple_spinner_dropdown_item) { @Override public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); if (position == getCount()) { ((TextView) v.findViewById(android.R.id.text1)).setText(""); ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed" } return v; } @Override public int getCount() { return super.getCount() - 1; // you dont display last item. It is used as hint. } }; rhesusadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); rhesusadapter.add("+"); rhesusadapter.add("-"); rhesusadapter.add("Rhesus"); inputRhesus.setAdapter(rhesusadapter); inputRhesus.setSelection(rhesusadapter.getCount()); //display hint inputGender = (Spinner) findViewById(R.id.gender_spinner); ArrayAdapter<String> genderadapter = new ArrayAdapter<String>(Register.this, android.R.layout.simple_spinner_dropdown_item) { @Override public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); if (position == getCount()) { ((TextView) v.findViewById(android.R.id.text1)).setText(""); ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed" } return v; } @Override public int getCount() { return super.getCount() - 1; // you dont display last item. It is used as hint. } }; genderadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); genderadapter.add("Male"); genderadapter.add("Female"); genderadapter.add("Gender"); inputGender.setAdapter(genderadapter); inputGender.setSelection(genderadapter.getCount()); //display hint /** * Gets spinner value */ // Session manager session = new SessionManager(getApplicationContext()); // Check if user is already logged in or not if (session.isLoggedIn()) { // User is already logged in. Take him to main activity Intent intent = new Intent(Register.this, UserPanel.class); startActivity(intent); finish(); } /** * Button which Switches back to the login screen on clicked **/ login = (Button) findViewById(R.id.bktologin); login.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), LoginActivity.class); startActivityForResult(myIntent, 0); finish(); } }); /** * Register Button click event. * A Toast is set to alert when the fields are empty. * Another toast is set to alert Username must be 5 characters. **/ btnRegister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if ((!inputUsername.getText().toString().equals("")) && (!inputPassword.getText().toString().equals("")) && (!inputFirstName.getText().toString().equals("")) && (!inputLastName.getText().toString().equals("")) && (!inputEmail.getText().toString().equals("")) && (!inputBloodType.getSelectedItem().toString().equals("")) && (!inputRhesus.getSelectedItem().toString().equals("")) && (!inputGender.getSelectedItem().toString().equals(""))) { if (inputUsername.getText().toString().length() > 4) { NetAsync(view); } else { Toast.makeText(getApplicationContext(), "Username must be a minimum of 5 characters", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "One or more fields are empty", Toast.LENGTH_SHORT) .show(); } } }); }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java
@SuppressWarnings("unchecked") private void refreshTestGroupsAndLog() { mLog = new StringBuilder(); Thread thread = new Thread() { @Override//from w w w . jav a2s.c o m public void run() { final boolean isNetBackend = IsNetBackend(); runOnUiThread(new Runnable() { @Override public void run() { ArrayAdapter<TestGroup> adapter = (ArrayAdapter<TestGroup>) mTestGroupSpinner.getAdapter(); adapter.clear(); adapter.add(new RoundTripTests()); adapter.add(new QueryTests()); adapter.add(new UpdateDeleteTests()); //adapter.add(new ClientSDKLoginTests()); adapter.add(new LoginTests(isNetBackend)); adapter.add(new MiscTests()); // adapter.add(new PushTests()); adapter.add(new CustomApiTests()); adapter.add(new SystemPropertiesTests(isNetBackend)); adapter.add(new EnhancedPushTests(isNetBackend)); adapter.add(new OfflineTests()); ArrayList<Pair<TestCase, String>> allTests = new ArrayList<Pair<TestCase, String>>(); ArrayList<Pair<TestCase, String>> allUnattendedTests = new ArrayList<Pair<TestCase, String>>(); for (int i = 0; i < adapter.getCount(); i++) { TestGroup group = adapter.getItem(i); allTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("Start of group: " + group.getName()), "Separator")); allUnattendedTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("Start of group: " + group.getName()), "Separator")); List<TestCase> testsForGroup = group.getTestCases(); for (TestCase test : testsForGroup) { allTests.add(new Pair<TestCase, String>(test, group.getName())); if (test.canRunUnattended()) { allUnattendedTests.add(new Pair<TestCase, String>(test, group.getName())); } } allTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("----" + group.getName() + "----"), "Separator")); allUnattendedTests.add(new Pair<TestCase, String>( Util.createSeparatorTest("----" + group.getName() + "----"), "Separator")); } int unattendedTestsIndex = adapter.getCount(); adapter.add( new CompositeTestGroup(TestGroup.AllUnattendedTestsGroupName, allUnattendedTests)); adapter.add(new CompositeTestGroup(TestGroup.AllTestsGroupName, allTests)); if (shouldRunUnattended()) { mTestGroupSpinner.setSelection(unattendedTestsIndex); selectTestGroup(unattendedTestsIndex); changeCheckAllTests(true); runTests(); } else { mTestGroupSpinner.setSelection(0); selectTestGroup(0); } } }); } }; thread.start(); }