Android: display EditText in menu

I am currently working on an mp3 library for Android. The thing is, I want the user to pick up the name of the playlist that he would like to add (useful?). Therefore, I created a context menu in the list of playlists, which allows the user to choose between 3 parameters, create, delete, rename. Why am I trying to do this to display the EditText field if the user presses "create" so that he can write a new playlist name. However, I cannot display it. Here are the listeners I made for the menu:

//creation onLongClickListener : display the menu on long lick playlistView.setOnLongClickListener(new OnLongClickListener(){ public boolean onLongClick(View v) { ((Activity) context).openContextMenu(v); return true; }}); //contextMenuListener of the view playlistView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener(){ public void onCreateContextMenu(ContextMenu cMenu, View v, ContextMenu.ContextMenuInfo menuInfo) { MenuInflater inflater = ((Activity) context).getMenuInflater(); inflater.inflate(R.menu.playlist_menu, cMenu); lastLongClickedView = v; }}); 

In the menu.xml file, I did this:

 <item android:id="@+id/playlist_create" android:title="Create a playlist" > <menu> <EditText android:id="@+id/playlist_choice" android:layout_height="wrap_content" android:layout_width="match_parent" android:hint="@string/playlist_name" android:lines="1" /> </menu> </item> 

I tried the element that it displayed, but EditText. I assume that the error I am making is pretty stupid, but I cannot find it :(

Thank you for your attention.

+4
source share
1 answer

Sorry, by no means .. you cannot define our own view in the menu. the main menu tag has only one subtag ie, item. using an element tag, we can only display an image or string

+2
source

Source: https://habr.com/ru/post/1413705/


All Articles