Контекстно меню в активността на списъка

Имам активност в списъка с адаптер за персонализиран масив и не мога да получа контекстно меню, когато натисна дълго върху елемент от списъка.

<TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
    <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp">
        <ListView
                android:id="@+id/list"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                />

    </FrameLayout>

оформление на елемент от списъка

    <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
        >
    <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    <TextView
            android:id="@+id/info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textSize="15sp"
            android:singleLine="true"
            android:ellipsize="marquee"
            android:scrollHorizontally = "true"
            android:maxWidth="200dp"
            />


    <LinearLayout
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:gravity="right"
            >
        <ImageButton
                android:id="@+id/button"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:background="@null"
                android:paddingRight="10dp"                
                android:paddingLeft="10dp"


                />
    </LinearLayout>

</LinearLayout>

В дейност

@Override
public void onCreate(Bundle savedInstanceState) {
   registerForContextMenu(getListView());
}

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.context_menu, menu);



  }

Защо не виждам контекстното меню? Какво правя грешно? Как да получите контекстно меню с адаптер за масив и ListActivity. Благодаря!


person Georgy Gobozov    schedule 18.10.2010    source източник


Отговори (2)



Трябва да зададете свойството LongClickable за първия файл с оформление на LinearLayout от елемент от списъка:

    <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:longClickable="true"
        >
...
person David Salgado    schedule 28.04.2012