Menu contextuel d'un ListFragment

Je suis en train de créer une application pour les tablettes avec un écran de trois fragments, chacun contenant une liste. Je voudrais activer les menus de contexte pour chaque liste, mais à chaque fois que j'essaie, que je reçois un arrêt inattendu d'un programme et de la Force de fermeture.

Qui suit est le code pertinent et xml qui fonctionne et qui me donne mon choix de trois fragments avec les listviews dans chaque, avant que j'essaie de l'ajouter au menu contextuel:

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp">

<fragment class="cdc.ListFragment.Fragment1"
    android:id="@+id/fragment1"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<fragment class="cdc.ListFragment.Fragment2"
    android:id="@+id/fragment2"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<fragment class="cdc.ListFragment.Fragment3" 
    android:id="@+id/fragment3"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

</LinearLayout>

fragment1.xml (les deux autres le sont aussi)

    <TextView
        android:id="@+id/txtHeader1"
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="@string/machines_header"
        android:textColor="#00ccff"
        android:background="#ff23cf"
        android:textSize="25dp" />

    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:drawSelectorOnTop="false"
        android:textSize="12dp" />

    <Button
        android:id="@+id/Button01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:minHeight="25dp"
        android:text="@string/menu_add_machine"
        android:textSize="15dp" >
    </Button>

</LinearLayout>

ListFragment.java

import android.app.Activity;
import android.os.Bundle;

public class ListFragmentExampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Fragment1.java (les deux autres sont similaires)

import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Fragment1 extends ListFragment {
    String[] presidents = { "Dwight D. Eisenhower", "John F. Kennedy",
            "Lyndon B. Johnson", "Richard Nixon", "Gerald Ford",
            "Jimmy Carter", "Ronald Reagan", "George H. W. Bush",
            "Bill Clinton", "George W. Bush", "Barack Obama" };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment1, container, false);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_1, presidents));
    }

}

Selon tout ce que j'ai lu, je devrais être en mesure de simplement ajouter

registerForContextMenu(getListView());

pour la méthode onCreate dans fragment1.java et ajouter le menu approprié code. Cependant, la seconde je l'ai ajoutez-le et essayez de le lancer, j'obtiens le déjà mentionné de verrouillage/crash.

N'importe qui ont des pointeurs/de l'aide pour cette situation?

OriginalL'auteur Barak | 2012-01-07