Example #1
0
  /** Initialize the views. */
  private void initializeUI() {
    setCustomContentView(R.layout.activity_add_city, R.string.screen_name_city_select);
    btnBack = (Button) findViewById(R.id.nav_back_button);
    btnLoaction = (Button) findViewById(R.id.nav_location_button);
    btnBack.setVisibility(View.VISIBLE);
    btnLoaction.setVisibility(View.VISIBLE);

    hotCityListGridView = (GridView) findViewById(R.id.hot_city_list_grid_view);
    searchCityEditText = (AutoCompleteTextView) findViewById(R.id.search_name_edit_text);

    defaultHotCityList = getResources().getStringArray(R.array.hot_city_list);
    hotCityListGridView.setAdapter(new CityAdapter());
    hotCityListGridView.setOnItemClickListener(onItemClickListener);
    searchCityEditText.addTextChangedListener(searchWatcher);

    adapter =
        new ArrayAdapter<String>(
            AddCitiyActivity.this, // 定义匹配源的adapter
            android.R.layout.simple_dropdown_item_1line,
            seachResultCityArrayList);
    searchCityEditText.setAdapter(adapter);
    searchCityEditText.setOnItemSelectedListener(onItemSelectedListener);

    btnBack.setOnClickListener(onClickListener);
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View shippingDetailsView = inflater.inflate(R.layout.shipping_details, container, false);

    Button placeOrder = (Button) shippingDetailsView.findViewById(R.id.placeOrder);

    phoneNumberField = (EditText) shippingDetailsView.findViewById(R.id.phone);
    phoneNumberField.setText(user.getPhone());

    firstNameField = (EditText) shippingDetailsView.findViewById(R.id.firstName);
    firstNameField.setText(user.getFirstName());

    lastNameField = (EditText) shippingDetailsView.findViewById(R.id.lastName);
    lastNameField.setText(user.getLastName());

    address1Field = (EditText) shippingDetailsView.findViewById(R.id.streetAddress1);
    address1Field.setText(user.getAddress1());

    address2Field = (EditText) shippingDetailsView.findViewById(R.id.streetAddress2);
    address2Field.setText(user.getAddress2());

    cityField = (EditText) shippingDetailsView.findViewById(R.id.city);
    cityField.setText(user.getCity());

    stateField = (AutoCompleteTextView) shippingDetailsView.findViewById(R.id.state);
    stateField.setText(user.getState());

    zipCodeField = (EditText) shippingDetailsView.findViewById(R.id.postalCode);
    zipCodeField.setText(user.getZipCode());

    countryField = (AutoCompleteTextView) shippingDetailsView.findViewById(R.id.country);
    user.setCountry(user.getCountry() != null ? user.getCountry() : "United States");
    countryField.setText(user.getCountry());
    countryField.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            loadStates();
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });

    placeOrder.setOnClickListener((b) -> placeOrder());

    loadCountries();
    loadStates();
    return shippingDetailsView;
  }
  private void setAdapterForPoiTypeEditText() {
    final Map<String, PoiType> subCategories = new LinkedHashMap<>();
    for (Map.Entry<String, PoiType> s : allTranslatedSubTypes.entrySet()) {
      if (!subCategories.containsKey(s.getKey())) {
        subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue());
      }
    }
    final ArrayAdapter<Object> adapter;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      adapter =
          new ArrayAdapter<>(
              getActivity(), R.layout.list_textview, subCategories.keySet().toArray());
    } else {
      TypedValue typedValue = new TypedValue();
      Resources.Theme theme = getActivity().getTheme();
      theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true);
      final int textColor = typedValue.data;

      adapter =
          new ArrayAdapter<Object>(
              getActivity(), R.layout.list_textview, subCategories.keySet().toArray()) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
              final View view = super.getView(position, convertView, parent);
              ((TextView) view.findViewById(R.id.textView)).setTextColor(textColor);
              return view;
            }
          };
    }
    poiTypeEditText.setAdapter(adapter);
    poiTypeEditText.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Object item = parent.getAdapter().getItem(position);
            LOG.debug("item=" + item);
            //noinspection SuspiciousMethodCalls
            if (subCategories.containsKey(item)) {
              //noinspection SuspiciousMethodCalls
              String keyName = subCategories.get(item).getKeyName();
              poiTypeEditText.setText(keyName);
            }
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });
  }