开发者

registerForContextMenu not working for a parent/child list view

I have a ListActivity which uses a custom ArrayAdapter defining 2 view types, for example

parent 1
- child 11
- child 12
parent 2
- child 21
parent 3
- child 31
- child 32

I have successfully implemented the display functionality I want, but when I register the list view with registerForContextMenu( getListView() ) in the ListActivity th开发者_运维百科e only views that open the Context Menu are the child views, instead I want a long click on the parent views to open the Context Menu. I've defined the parent view types as enabled and the child as disabled, this only makes both of them ignore the long press event. Any ideas? I was going to define the OnLongClick event on the parent views, but I'm not sure how to get ahold of the MenuInflator for the Activity (I have my ArrayAdapter defined in it's own class), should I pass the MenuInflator into my ArrayAdapter?? This seems a little heavy handed, but it may work.

Here's my onCreate call

@Override
protected void onCreate( Bundle savedInstanceState ) 
{
    super.onCreate( savedInstanceState );
    setContentView( R.layout.workout_activity );

    _pactAdapter = new WorkoutItemAdapter( this ); 
    setListAdapter( _pactAdapter );
    registerForContextMenu( getListView() );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜