Custom ArrayAdapterでListViewを構成するとき、Context Menuが表示されない時の解決

Androidの基本ArrayAdapter以外に、このクラスを継承したカスタムArrayAdapterでListViewを構成すると、Context Menuが呼び出されない問題があります。これはListViewの中のViewが長いクリックに反応しないためおこる現象です。これを解決するためにはカスタムArrayAdapterのgetViewメソッドに以下のような処理を加えます。

カスタムArrayAdapterのgetViewで得るviewの名前を仮にtargetViewだとして、

targetView.setLongClickable(true);

のように長いクリックに対するフラグをtrueに設定します。これでListViewが正常にContext Menuを表示するようになります。

作成者: kkc0923

KANOTYPE管理者。

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください