安卓:在菜单中显示一个EditText [英] Android : Display an EditText in a menu

查看:165
本文介绍了安卓:在菜单中显示一个EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个MP3库为Android。事情是,我希望用户拿起他想添加播放列表的名称(用是吗?)。因此,我创建的播放列表,它允许用户在3个选项中进行选择,创建,删除,重命名上下文菜单。为什么我试图做的是,如果用户点击创建,显示一个EditText场,这样他就可以写入新的播放列表的名称。但是,我不能管理来显示它。下面是我对菜单进行的监听器:

I'm currently working on a mp3 library for Android. Thing is, I want the user to pick up the name of the playlist he would like to add (useful innit ?). Therefore, I created a context menu on the playlists list which allows the user to choose between 3 options, create, delete, rename. Why I'm trying to do is to display an EditText field if the user clicks on "create", so that he can write the new playlist's name. However, I can't manage to 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;
    }});

在我这样做的menu.xml文件文件:

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>

我试图用一个项目,它的显示,但EditText上。我认为我做的错误是pretty愚蠢但我不能找到它:(

I tried with an item, it's displayed, but the EditText. I assume the mistake I'm making is pretty stupid yet I can't find it :(

感谢您的关注。

推荐答案

对不起,没办法..你不能定义自己的菜单视图。菜单主标签只有一个子标签即,项目。使用item标签,我们只能显示图像或串

Sorry, no way.. you cant define our own View in the menu. the menu main tag has only one subtag i.e,item. using item tag we can only display image or string

这篇关于安卓:在菜单中显示一个EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆