0

I tried using AutoCompleteTextView to do this.

               <com.google.android.material.textfield.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/_64sdp"
                            android:layout_marginTop="@dimen/_10sdp"
                            android:layout_marginLeft="@dimen/_5sdp"
                            android:layout_marginRight="@dimen/_5sdp"
                            android:background="@color/colorWhite"
                            android:elevation="@dimen/_2sdp"
                            android:textColorHint="@color/colorDarkGreyOne">

                            <AutoCompleteTextView
                                android:id="@+id/autoCompleteTvCountry"
                                style="@style/StyleEditText"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:drawableRight="@drawable/ic_arrow_down"
                                android:hint="@string/label_country"
                                android:background="@android:color/transparent"
                                android:paddingTop="@dimen/_10sdp"
                                android:paddingLeft="@dimen/_10sdp"
                                android:layout_marginRight="@dimen/_10sdp"
                                android:textSize="17.3sp"/>

                        </com.google.android.material.textfield.TextInputLayout>




 and using array adapter:

  ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, countryNameList);
    AutoCompleteTextView mTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTvCountry);
    mTextView.setAdapter(dataAdapter);
    mTextView.setKeyListener(null);
    mTextView.setOnTouchListener(new View.OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event){
            ((AutoCompleteTextView) v).showDropDown();
            return false;
        }
    });

I am facing two problems: 1. unable to get the @Override method onItemSelected which is required and 2. In the dropdown list of country, countries are too close like below image

enter image description here

how to solve this problem or any other way to do spinner with floating lebel having @Override method onItemSelected?

TB13
  • 367
  • 13
  • 23

0 Answers0