3

まず、私の英語はあまり得意ではありません。私はListView これと別のようなものを持っていTextViewます。私の問題は、そこに置きたいのですcontextMenuが、できません。これで多くの時間を失いましたが、解決策が見つかりません。

とを使用 registerForContextMenu(listViewTotes)しました。onCreateContextMenuonContextItemSelected

ありがとう!

4

1 に答える 1

1

OnItemLongClickListener() を使用することをお勧めします。どうやら、OnItemClickListener() は registerForContextMenu(arg0) に対して応答しませんでした。

OnItemLongClickListener() の例を使用する場合、コードは次のようになります。

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_main);

    listView = (ListView) findViewById(R.id.my_list);
    adapter = new MyAdapter(this,getModel());
    listView.setAdapter(adapter);
    listView.setOnItemLongClickListener(new PlayListOnItemLongClickListener());
}

private class PlayListOnItemLongClickListener implements AdapterView.OnItemLongClickListener {
    public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        registerForContextMenu(arg0);

        return false;
    }
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    getMenuInflater().inflate(R.menu.context_playlist_operation, menu);
    menu.setHeaderIcon(R.drawable.ic_launcher);
    menu.setHeaderTitle("What do you want to do");
}

/ListViewTest/res/menu/context_playlist_operation.xml 内

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <group>
        <item
            android:id="@+id/context_playlist_remove_playlist"
            android:title="@string/app_name"
            />
    </group>
</menu>
于 2012-10-18T03:27:17.063 に答える