List of usage examples for android.widget ArrayAdapter getCount
@Override public int getCount()
From source file:com.nttec.everychan.ui.ShareActivity.java
private void handleIntent(Intent intent) { ArrayAdapter<Pair<TabModel, SerializablePage>> adapter = new ArrayAdapter<Pair<TabModel, SerializablePage>>( this, 0) { private final int drawablePadding = (int) (getResources().getDisplayMetrics().density * 5 + 0.5f); @Override// w ww. j av a 2 s . c om public View getView(int position, View convertView, ViewGroup parent) { View view = convertView == null ? getLayoutInflater().inflate(android.R.layout.simple_list_item_1, parent, false) : convertView; TextView tv = (TextView) view.findViewById(android.R.id.text1); tv.setEllipsize(TextUtils.TruncateAt.END); tv.setSingleLine(); tv.setText(getItem(position).getLeft().title); tv.setCompoundDrawablesWithIntrinsicBounds(MainApplication.getInstance() .getChanModule(getItem(position).getLeft().pageModel.chanName).getChanFavicon(), null, null, null); tv.setCompoundDrawablePadding(drawablePadding); return view; } }; for (TabModel tab : MainApplication.getInstance().tabsState.tabsArray) { if (tab.type == TabModel.TYPE_NORMAL && tab.pageModel.type != UrlPageModel.TYPE_SEARCHPAGE) { SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash); if (page != null) { adapter.add(Pair.of(tab, page)); } } } if (adapter.getCount() == 0) { for (Database.HistoryEntry entity : MainApplication.getInstance().database.getHistory()) { try { TabModel tab = new TabModel(); tab.title = entity.title; tab.type = TabModel.TYPE_NORMAL; tab.webUrl = entity.url; tab.pageModel = UrlHandler.getPageModel(entity.url); tab.hash = ChanModels.hashUrlPageModel(tab.pageModel); SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash); if (page != null) { adapter.add(Pair.of(tab, page)); } } catch (Exception e) { Logger.e(TAG, e); } } if (adapter.getCount() == 0) { Toast.makeText(this, R.string.share_no_tabs, Toast.LENGTH_LONG).show(); finish(); return; } } if (PostingService.isNowPosting()) { Toast.makeText(this, R.string.posting_now_posting, Toast.LENGTH_LONG).show(); finish(); return; } selectedFile = null; if (intent != null) { Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { File file = UriFileUtils.getFile(this, uri); if (file != null) { selectedFile = file; } } } if (selectedFile == null) { Toast.makeText(this, R.string.postform_cannot_attach, Toast.LENGTH_LONG).show(); finish(); return; } setListAdapter(adapter); }
From source file:com.esri.arcgisruntime.sample.offlinegeocode.MainActivity.java
private void setSearchView() { mSearchview = (SearchView) findViewById(R.id.searchView1); mSearchview.setIconifiedByDefault(true); mSearchview.setQueryHint(getResources().getString(R.string.search_hint)); mSearchview.setOnQueryTextListener(new OnQueryTextListener() { @Override//from ww w.j a v a2 s. c o m public boolean onQueryTextSubmit(String query) { hideKeyboard(); geoCodeTypedAddress(query); mSearchview.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); mSpinner = (Spinner) findViewById(R.id.spinner); // Create an ArrayAdapter using the string array and a default spinner layout final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(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()) { mSearchview.clearFocus(); } return v; } @Override public int getCount() { return super.getCount() - 1; // you dont display last item. It is used as hint. } }; // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.addAll(getResources().getStringArray(R.array.suggestion_items)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // set vertical offset to spinner dropdown for API less than 21 mSpinner.setDropDownVerticalOffset(80); } // Apply the adapter to the spinner mSpinner.setAdapter(adapter); mSpinner.setSelection(adapter.getCount()); mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == adapter.getCount()) { mSearchview.clearFocus(); } else { hideKeyboard(); mSearchview.setQuery(getResources().getStringArray(R.array.suggestion_items)[position], false); geoCodeTypedAddress(getResources().getStringArray(R.array.suggestion_items)[position]); mSearchview.setIconified(false); mSearchview.clearFocus(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.example.yudiandrean.socioblood.FeedActivity.java
@SuppressLint("NewApi") @Override/*from www. ja v a 2s . c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Dialog d = new Dialog(context); setContentView(R.layout.feed_activity); postrequest = (TextView) findViewById(R.id.editText); WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE); final int width, height; ActionBar.LayoutParams params; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) { width = manager.getDefaultDisplay().getWidth(); height = manager.getDefaultDisplay().getHeight(); } else { Point point = new Point(); manager.getDefaultDisplay().getSize(point); width = point.x; height = point.y; } 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(FeedActivity.this, LoginActivity.class); startActivity(intent); finish(); } listView = (ListView) findViewById(R.id.list); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer); feedItems = new ArrayList<FeedItem>(); listAdapter = new FeedListAdapter(this, feedItems); listView.setAdapter(listAdapter); swipeRefreshLayout.setOnRefreshListener(this); // add button listener postrequest.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { try { d.requestWindowFeature(Window.FEATURE_NO_TITLE); d.setContentView(R.layout.post_request); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getWindow().getAttributes()); lp.width = width; lp.height = height; d.getWindow().setAttributes(lp); } catch (AndroidRuntimeException e) { } catch (Exception e) { } final Spinner rhesusspinner = (Spinner) d.findViewById(R.id.rhesus_spinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(FeedActivity.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. } }; adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.add("+"); adapter.add("-"); adapter.add("Rhesus"); rhesusspinner.setAdapter(adapter); rhesusspinner.setSelection(adapter.getCount()); //display hint final Spinner bloodspinner = (Spinner) d.findViewById(R.id.bloodtype_spinner); ArrayAdapter<String> bloodadapter = new ArrayAdapter<String>(FeedActivity.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("Desired Type"); bloodspinner.setAdapter(bloodadapter); bloodspinner.setSelection(bloodadapter.getCount()); //display hint //Buttons-Editexts Button btnpost = (Button) d.findViewById(R.id.post); final EditText userInput = (EditText) d.findViewById(R.id.editTextDialogUserInput); d.show(); btnpost.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (bloodspinner.getSelectedItem().toString().equals("Desired Type")) { Toast.makeText(getApplicationContext(), "Input Blood Type!", Toast.LENGTH_SHORT).show(); } else if (rhesusspinner.getSelectedItem().toString().equals("Rhesus")) { Toast.makeText(getApplicationContext(), "Input Rhesus!", Toast.LENGTH_SHORT).show(); } else if (userInput.getText().toString().equals("")) { Toast.makeText(getApplicationContext(), "Input your request message!", Toast.LENGTH_SHORT).show(); } else { int uid = session.currentUID(); String message = userInput.getText().toString(); String post_bloodtype = bloodspinner.getSelectedItem().toString(); String post_rhesus = rhesusspinner.getSelectedItem().toString(); NetAsync(d, view, uid, message, post_bloodtype, post_rhesus); } } }); } }); // // We first check for cached request // Cache cache = FeedController.getInstance().getRequestQueue().getCache(); // Entry entry = cache.get(URL_FEED); // if (entry != null) { // // fetch the data from cache // try { // String data = new String(entry.data, "UTF-8"); // try { // parseJsonFeed(new JSONObject(data)); // } catch (JSONException e) { // e.printStackTrace(); // } // } catch (UnsupportedEncodingException e) { // e.printStackTrace(); // } // // } else { // making fresh volley request and getting json /** * Showing Swipe Refresh animation on activity create * As animation won't start on onCreate, post runnable is used */ swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); getTimelineAsync(); } }); }
From source file:org.mozilla.gecko.AutoCompletePopup.java
public void show(JSONArray suggestions, JSONArray rect, double zoom) { ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.autocomplete_list_item); for (int i = 0; i < suggestions.length(); i++) { try {// www . java2 s . c o m adapter.add(suggestions.get(i).toString()); } catch (JSONException e) { Log.i(LOGTAG, "JSONException: " + e); } } setAdapter(adapter); if (!isShown()) { setVisibility(View.VISIBLE); startAnimation(mAnimation); } if (mLayout == null) { mLayout = (RelativeLayout.LayoutParams) getLayoutParams(); mWidth = mLayout.width; mHeight = mLayout.height; } int left = 0; int top = 0; int width = 0; int height = 0; try { left = (int) (rect.getDouble(0) * zoom); top = (int) (rect.getDouble(1) * zoom); width = (int) (rect.getDouble(2) * zoom); height = (int) (rect.getDouble(3) * zoom); } catch (JSONException e) { } int listWidth = mWidth; int listHeight = mHeight; int listLeft = left < 0 ? 0 : left; int listTop = top + height; FloatSize viewport = GeckoApp.mAppContext.getLayerController().getViewportSize(); // Late initializing variable to allow DisplayMetrics not to be null and avoid NPE if (sMinWidth == 0) { DisplayMetrics metrics = new DisplayMetrics(); GeckoApp.mAppContext.getWindowManager().getDefaultDisplay().getMetrics(metrics); sMinWidth = (int) (AUTOCOMPLETE_MIN_WIDTH_IN_DPI * metrics.density); sRowHeight = (int) (AUTOCOMPLETE_ROW_HEIGHT_IN_DPI * metrics.density); } // If the textbox is smaller than the screen-width, // shrink the list's width if ((left + width) < viewport.width) listWidth = left < 0 ? left + width : width; // listWidth can be negative if it is a constant - FILL_PARENT or MATCH_PARENT if (listWidth >= 0 && listWidth < sMinWidth) { listWidth = sMinWidth; if ((listLeft + listWidth) > viewport.width) listLeft = (int) (viewport.width - listWidth); } listHeight = sRowHeight * adapter.getCount(); // The text box doesnt fit below if ((listTop + listHeight) > viewport.height) { // Find where the maximum space is, and fit it there if ((viewport.height - listTop) > top) { // Shrink the height to fit it below the text-box listHeight = (int) (viewport.height - listTop); } else { if (listHeight < top) { // No shrinking needed to fit on top listTop = (top - listHeight); } else { // Shrink to available space on top listTop = 0; listHeight = top; } } } mLayout = new RelativeLayout.LayoutParams(listWidth, listHeight); mLayout.setMargins(listLeft, listTop, 0, 0); setLayoutParams(mLayout); requestLayout(); }
From source file:de.uni_koblenz_landau.apow.PatientDetailEditFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.patient_detail_edit_fragment, container, false); // Create UI references. mBirthDateDialog = (DateDialogFragment) getFragmentManager().findFragmentByTag(BIRTHDATE_DIALOG_ID); if (mBirthDateDialog != null) { mBirthDateDialog.setListener(this); }/* w ww. j a v a2 s.com*/ mDeathDateDialog = (DateDialogFragment) getFragmentManager().findFragmentByTag(DEATHDATE_DIALOG_ID); if (mDeathDateDialog != null) { mDeathDateDialog.setListener(this); } mIdentifierView = (EditText) view.findViewById(R.id.patient_detail_edit_identifier); mNamePrefixView = (EditText) view.findViewById(R.id.patient_detail_edit_name_prefix); mGivenNameView = (EditText) view.findViewById(R.id.patient_detail_edit_name_given_name); mMiddleNameView = (EditText) view.findViewById(R.id.patient_detail_edit_name_middle_name); mFamilyNamePrefixView = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name_prefix); mFamilyNameView = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name); mFamilyName2View = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name2); mFamilyNameSuffixView = (EditText) view.findViewById(R.id.patient_detail_edit_name_family_name_suffix); mDegreeView = (EditText) view.findViewById(R.id.patient_detail_edit_name_degree); mGenderView = (Spinner) view.findViewById(R.id.patient_detail_edit_gender); mBirthdateView = (TextView) view.findViewById(R.id.patient_detail_edit_birthdate); mBirthdateEstimatedView = (CheckBox) view.findViewById(R.id.patient_detail_edit_birthdate_estimated); mAddress1View = (EditText) view.findViewById(R.id.patient_detail_edit_address_address1); mAddress2View = (EditText) view.findViewById(R.id.patient_detail_edit_address_address2); mCityVillageView = (EditText) view.findViewById(R.id.patient_detail_edit_address_cityvillage); mDistrictsView = (Spinner) view.findViewById(R.id.patient_detail_edit_address_district); mRegionsView = (Spinner) view.findViewById(R.id.patient_detail_edit_address_region); mRegionsView.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { Region region = (Region) parent.getItemAtPosition(pos); ArrayAdapter<District> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, region.getDistricts()); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDistrictsView.setAdapter(adapter); if (parent.getTag() != null) { mDistrictsView.setSelection((int) parent.getTag()); parent.setTag(null); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); mCountryView = (EditText) view.findViewById(R.id.patient_detail_edit_address_country); mLongitudeView = (EditText) view.findViewById(R.id.patient_detail_edit_address_longitude); mLatitudeView = (EditText) view.findViewById(R.id.patient_detail_edit_address_latitude); mDeathdateView = (TextView) view.findViewById(R.id.patient_detail_edit_deathdate); mDeadLayout = (LinearLayout) view.findViewById(R.id.patient_detail_edit_dead_group); mDeadLayout = (LinearLayout) view.findViewById(R.id.patient_detail_edit_dead_group); mDeadView = (CheckBox) view.findViewById(R.id.patient_detail_edit_dead); mDeadView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { CheckBox dead = (CheckBox) v; if (dead.isChecked()) { mDeadLayout.setVisibility(View.VISIBLE); } else { mDeadLayout.setVisibility(View.GONE); } } }); // Restore UI from saved instance or load data. if (savedInstanceState != null) { mPatient = (Patient) savedInstanceState.getSerializable(ARG_PATIENT); if (mPatient != null) { mRegions = (List<Region>) savedInstanceState.getSerializable(ARG_REGIONS); ArrayAdapter<Region> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, mRegions); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mRegionsView.setAdapter(adapter); ArrayAdapter<District> adapter1 = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, mRegions.get(0).getDistricts()); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDistrictsView.setAdapter(adapter1); String selectedRegion = savedInstanceState.getString(ARG_SELECTED_REGION); String selectedDistrict = savedInstanceState.getString(ARG_SELECTED_DISTRICT); for (int i = 0; i < adapter.getCount(); i++) { Region region = adapter.getItem(i); if (region.getRegionName().equals(selectedRegion)) { for (int j = 0; j < region.getDistricts().size(); j++) { if (region.getDistricts().get(j).getDistrictName().equals(selectedDistrict)) { mRegionsView.setTag(j); mRegionsView.setSelection(i, false); adapter1 = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, region.getDistricts()); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDistrictsView.setAdapter(adapter1); mDistrictsView.setSelection(j, false); break; } } break; } } if (savedInstanceState.getBoolean(ARG_DEAD)) { mDeadLayout.setVisibility(View.VISIBLE); } else { mDeadLayout.setVisibility(View.GONE); } } } else { loadPatient(); } return view; }
From source file:de.uni_koblenz_landau.apow.PatientDetailEditFragment.java
/** * Called by EncounterDetailTask, when loading is finished. *//* w w w. ja v a2 s . c o m*/ @Override public void onPatientFetched(Patient patient, List<Region> regions) { mPatientDetailTask = null; // If result is not empty, update UI, else show error message. if (regions != null) { mRegions = regions; ArrayAdapter<Region> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, regions); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mRegionsView.setAdapter(adapter); ArrayAdapter<District> adapter1 = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, regions.get(0).getDistricts()); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDistrictsView.setAdapter(adapter1); if (patient != null) { mPatient = patient; if (mPatient.getPatientIdentifier() != null) { Helper.setViewText(mIdentifierView, mPatient.getPatientIdentifier().getIdentifier()); } if (mPatient.getPersonName() != null) { getActivity().setTitle(mPatient.getPersonName().getFullName()); Helper.setViewText(mNamePrefixView, mPatient.getPersonName().getPrefix()); Helper.setViewText(mGivenNameView, mPatient.getPersonName().getGivenName()); Helper.setViewText(mMiddleNameView, mPatient.getPersonName().getMiddleName()); Helper.setViewText(mFamilyNamePrefixView, mPatient.getPersonName().getFamilyNamePrefix()); Helper.setViewText(mFamilyNameView, mPatient.getPersonName().getFamilyName()); Helper.setViewText(mFamilyName2View, mPatient.getPersonName().getFamilyName2()); Helper.setViewText(mFamilyNameSuffixView, mPatient.getPersonName().getFamilyNameSuffix()); Helper.setViewText(mDegreeView, mPatient.getPersonName().getDegree()); } if (mPatient.getGender() != null) { switch (mPatient.getGender()) { case "U": mGenderView.setSelection(0); break; case "F": mGenderView.setSelection(1); break; case "M": mGenderView.setSelection(2); break; } } else { mGenderView.setSelection(0); } if (mPatient.getBirthdate() != null) { Helper.setViewText(mBirthdateView, Helper.dateToLocaleString(mPatient.getBirthdate(), getActivity())); } mBirthdateEstimatedView.setChecked(mPatient.isBirthdateEstimated()); if (mPatient.getPersonAddress() != null) { Helper.setViewText(mAddress1View, mPatient.getPersonAddress().getAddress1()); Helper.setViewText(mAddress2View, mPatient.getPersonAddress().getAddress2()); Helper.setViewText(mCityVillageView, mPatient.getPersonAddress().getCityVillage()); String selectedRegion = mPatient.getPersonAddress().getStateProvince(); String selectedDistrict = mPatient.getPersonAddress().getCountyDistrict(); for (int i = 0; i < adapter.getCount(); i++) { Region region = adapter.getItem(i); if (region.getRegionName().equals(selectedRegion)) { for (int j = 0; j < region.getDistricts().size(); j++) { if (region.getDistricts().get(j).getDistrictName().equals(selectedDistrict)) { mRegionsView.setTag(j); mRegionsView.setSelection(i, false); adapter1 = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, region.getDistricts()); adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDistrictsView.setAdapter(adapter1); mDistrictsView.setSelection(j, false); break; } } break; } } Helper.setViewText(mCountryView, mPatient.getPersonAddress().getCountry()); Helper.setViewText(mLongitudeView, mPatient.getPersonAddress().getLongitude()); Helper.setViewText(mLatitudeView, mPatient.getPersonAddress().getLatitude()); } mDeadView.setChecked(mPatient.getDead()); if (mPatient.getDead()) { if (mPatient.getDeathDate() != null) { Helper.setViewText(mDeathdateView, Helper.dateToLocaleString(mPatient.getDeathDate(), getActivity())); } mDeadLayout.setVisibility(View.VISIBLE); } else { mDeadLayout.setVisibility(View.GONE); } } else { mPatient = new Patient(); PatientIdentifier patientIdentifier = new PatientIdentifier(); PatientIdentifierType patientIdentifierType = new PatientIdentifierType(); patientIdentifierType.setName(Constants.IDENTIFIER_TYPE_NAME); patientIdentifier.setIdentifierType(patientIdentifierType); mPatient.addIdentifier(patientIdentifier); PersonName personName = new PersonName(); mPatient.addName(personName); PersonAddress personAddress = new PersonAddress(); mPatient.addAddress(personAddress); } } else { Toast.makeText(getActivity(), R.string.error_database, Toast.LENGTH_SHORT).show(); } }