How to create EditText with menu underneath?












0














I want to create EditText with clickable menu underneath. User should be able to write his own custom text into EditText or choose from predefined options.



I though about adding recyclerView under EditText, but for 4-5 options its waste of recylerView. Is there any way to do it better (I dont want to write a lot of code for this feature).



enter image description here










share|improve this question


















  • 3




    Check the tutorial of AutoCompleteTextView: tutorialspoint.com/android/…
    – Nabin Bhandari
    Nov 13 '18 at 9:27
















0














I want to create EditText with clickable menu underneath. User should be able to write his own custom text into EditText or choose from predefined options.



I though about adding recyclerView under EditText, but for 4-5 options its waste of recylerView. Is there any way to do it better (I dont want to write a lot of code for this feature).



enter image description here










share|improve this question


















  • 3




    Check the tutorial of AutoCompleteTextView: tutorialspoint.com/android/…
    – Nabin Bhandari
    Nov 13 '18 at 9:27














0












0








0







I want to create EditText with clickable menu underneath. User should be able to write his own custom text into EditText or choose from predefined options.



I though about adding recyclerView under EditText, but for 4-5 options its waste of recylerView. Is there any way to do it better (I dont want to write a lot of code for this feature).



enter image description here










share|improve this question













I want to create EditText with clickable menu underneath. User should be able to write his own custom text into EditText or choose from predefined options.



I though about adding recyclerView under EditText, but for 4-5 options its waste of recylerView. Is there any way to do it better (I dont want to write a lot of code for this feature).



enter image description here







android kotlin android-edittext






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 9:25









martin1337martin1337

1811112




1811112








  • 3




    Check the tutorial of AutoCompleteTextView: tutorialspoint.com/android/…
    – Nabin Bhandari
    Nov 13 '18 at 9:27














  • 3




    Check the tutorial of AutoCompleteTextView: tutorialspoint.com/android/…
    – Nabin Bhandari
    Nov 13 '18 at 9:27








3




3




Check the tutorial of AutoCompleteTextView: tutorialspoint.com/android/…
– Nabin Bhandari
Nov 13 '18 at 9:27




Check the tutorial of AutoCompleteTextView: tutorialspoint.com/android/…
– Nabin Bhandari
Nov 13 '18 at 9:27












2 Answers
2






active

oldest

votes


















0














AutoCompleteTextView is a component used to show suggestions while writing in an editable text field. The suggestions list is shown in a drop-down menu from which a user can select the desired item. The list of suggestions is obtained from an adapter and it appears only after a number of characters that are specified in the threshold.



Here is a simple example of AutoCompleteTextView:



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
android:text="X" />

<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView"
android:layout_marginLeft="36dp"
android:layout_marginTop="17dp"
android:ems="10"
android:text="">

<requestFocus />
</AutoCompleteTextView>

</RelativeLayout>


The MainActivity.java is defined below.



 public class MainActivity extends Activity {
String animals = {"Ant", "Bbird", "Cat"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Creating the instance of ArrayAdapter containing list of fruit names
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.select_dialog_item, animals);
//Getting the instance of AutoCompleteTextView
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
actv.setThreshold(1);//will start working from first character
actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
actv.setTextColor(Color.BLACK);

}
}





share|improve this answer





























    0














    try this,
    xml



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="State:" />

    <AutoCompleteTextView
    android:id="@+id/autoCompleteTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />




    java



    public class MainActivity extends AppCompatActivity {
    AutoCompleteTextView autoCompleteTextView;
    String arr={"used","new","repaired"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    autoCompleteTextView=findViewById(R.id.autoCompleteTextView);
    ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,arr);
    autoCompleteTextView.setAdapter(aa);
    }


    }






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277708%2fhow-to-create-edittext-with-menu-underneath%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      AutoCompleteTextView is a component used to show suggestions while writing in an editable text field. The suggestions list is shown in a drop-down menu from which a user can select the desired item. The list of suggestions is obtained from an adapter and it appears only after a number of characters that are specified in the threshold.



      Here is a simple example of AutoCompleteTextView:



      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin"
      tools:context=".MainActivity">

      <TextView
      android:id="@+id/textView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:layout_marginTop="15dp"
      android:text="X" />

      <AutoCompleteTextView
      android:id="@+id/autoCompleteTextView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/textView"
      android:layout_marginLeft="36dp"
      android:layout_marginTop="17dp"
      android:ems="10"
      android:text="">

      <requestFocus />
      </AutoCompleteTextView>

      </RelativeLayout>


      The MainActivity.java is defined below.



       public class MainActivity extends Activity {
      String animals = {"Ant", "Bbird", "Cat"};

      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      //Creating the instance of ArrayAdapter containing list of fruit names
      ArrayAdapter<String> adapter = new ArrayAdapter<String>
      (this, android.R.layout.select_dialog_item, animals);
      //Getting the instance of AutoCompleteTextView
      AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
      actv.setThreshold(1);//will start working from first character
      actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
      actv.setTextColor(Color.BLACK);

      }
      }





      share|improve this answer


























        0














        AutoCompleteTextView is a component used to show suggestions while writing in an editable text field. The suggestions list is shown in a drop-down menu from which a user can select the desired item. The list of suggestions is obtained from an adapter and it appears only after a number of characters that are specified in the threshold.



        Here is a simple example of AutoCompleteTextView:



        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">

        <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="15dp"
        android:text="X" />

        <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView"
        android:layout_marginLeft="36dp"
        android:layout_marginTop="17dp"
        android:ems="10"
        android:text="">

        <requestFocus />
        </AutoCompleteTextView>

        </RelativeLayout>


        The MainActivity.java is defined below.



         public class MainActivity extends Activity {
        String animals = {"Ant", "Bbird", "Cat"};

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //Creating the instance of ArrayAdapter containing list of fruit names
        ArrayAdapter<String> adapter = new ArrayAdapter<String>
        (this, android.R.layout.select_dialog_item, animals);
        //Getting the instance of AutoCompleteTextView
        AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
        actv.setThreshold(1);//will start working from first character
        actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
        actv.setTextColor(Color.BLACK);

        }
        }





        share|improve this answer
























          0












          0








          0






          AutoCompleteTextView is a component used to show suggestions while writing in an editable text field. The suggestions list is shown in a drop-down menu from which a user can select the desired item. The list of suggestions is obtained from an adapter and it appears only after a number of characters that are specified in the threshold.



          Here is a simple example of AutoCompleteTextView:



          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          android:paddingBottom="@dimen/activity_vertical_margin"
          tools:context=".MainActivity">

          <TextView
          android:id="@+id/textView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginTop="15dp"
          android:text="X" />

          <AutoCompleteTextView
          android:id="@+id/autoCompleteTextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/textView"
          android:layout_marginLeft="36dp"
          android:layout_marginTop="17dp"
          android:ems="10"
          android:text="">

          <requestFocus />
          </AutoCompleteTextView>

          </RelativeLayout>


          The MainActivity.java is defined below.



           public class MainActivity extends Activity {
          String animals = {"Ant", "Bbird", "Cat"};

          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

          //Creating the instance of ArrayAdapter containing list of fruit names
          ArrayAdapter<String> adapter = new ArrayAdapter<String>
          (this, android.R.layout.select_dialog_item, animals);
          //Getting the instance of AutoCompleteTextView
          AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
          actv.setThreshold(1);//will start working from first character
          actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
          actv.setTextColor(Color.BLACK);

          }
          }





          share|improve this answer












          AutoCompleteTextView is a component used to show suggestions while writing in an editable text field. The suggestions list is shown in a drop-down menu from which a user can select the desired item. The list of suggestions is obtained from an adapter and it appears only after a number of characters that are specified in the threshold.



          Here is a simple example of AutoCompleteTextView:



          <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          android:paddingBottom="@dimen/activity_vertical_margin"
          tools:context=".MainActivity">

          <TextView
          android:id="@+id/textView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_alignParentTop="true"
          android:layout_marginTop="15dp"
          android:text="X" />

          <AutoCompleteTextView
          android:id="@+id/autoCompleteTextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentLeft="true"
          android:layout_below="@+id/textView"
          android:layout_marginLeft="36dp"
          android:layout_marginTop="17dp"
          android:ems="10"
          android:text="">

          <requestFocus />
          </AutoCompleteTextView>

          </RelativeLayout>


          The MainActivity.java is defined below.



           public class MainActivity extends Activity {
          String animals = {"Ant", "Bbird", "Cat"};

          @Override
          protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);

          //Creating the instance of ArrayAdapter containing list of fruit names
          ArrayAdapter<String> adapter = new ArrayAdapter<String>
          (this, android.R.layout.select_dialog_item, animals);
          //Getting the instance of AutoCompleteTextView
          AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
          actv.setThreshold(1);//will start working from first character
          actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
          actv.setTextColor(Color.BLACK);

          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 9:39









          Sultan MahmudSultan Mahmud

          23017




          23017

























              0














              try this,
              xml



              <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center"
              android:orientation="vertical">

              <TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="State:" />

              <AutoCompleteTextView
              android:id="@+id/autoCompleteTextView"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />




              java



              public class MainActivity extends AppCompatActivity {
              AutoCompleteTextView autoCompleteTextView;
              String arr={"used","new","repaired"};
              @Override
              protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main2);
              autoCompleteTextView=findViewById(R.id.autoCompleteTextView);
              ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,arr);
              autoCompleteTextView.setAdapter(aa);
              }


              }






              share|improve this answer


























                0














                try this,
                xml



                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="State:" />

                <AutoCompleteTextView
                android:id="@+id/autoCompleteTextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />




                java



                public class MainActivity extends AppCompatActivity {
                AutoCompleteTextView autoCompleteTextView;
                String arr={"used","new","repaired"};
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main2);
                autoCompleteTextView=findViewById(R.id.autoCompleteTextView);
                ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,arr);
                autoCompleteTextView.setAdapter(aa);
                }


                }






                share|improve this answer
























                  0












                  0








                  0






                  try this,
                  xml



                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:gravity="center"
                  android:orientation="vertical">

                  <TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="State:" />

                  <AutoCompleteTextView
                  android:id="@+id/autoCompleteTextView"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" />




                  java



                  public class MainActivity extends AppCompatActivity {
                  AutoCompleteTextView autoCompleteTextView;
                  String arr={"used","new","repaired"};
                  @Override
                  protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_main2);
                  autoCompleteTextView=findViewById(R.id.autoCompleteTextView);
                  ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,arr);
                  autoCompleteTextView.setAdapter(aa);
                  }


                  }






                  share|improve this answer












                  try this,
                  xml



                  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:gravity="center"
                  android:orientation="vertical">

                  <TextView
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="State:" />

                  <AutoCompleteTextView
                  android:id="@+id/autoCompleteTextView"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content" />




                  java



                  public class MainActivity extends AppCompatActivity {
                  AutoCompleteTextView autoCompleteTextView;
                  String arr={"used","new","repaired"};
                  @Override
                  protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_main2);
                  autoCompleteTextView=findViewById(R.id.autoCompleteTextView);
                  ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_list_item_1,arr);
                  autoCompleteTextView.setAdapter(aa);
                  }


                  }







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 9:36









                  user5607081user5607081

                  419




                  419






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277708%2fhow-to-create-edittext-with-menu-underneath%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine