How to attach GestureDetector to a ListPreference?

前端 未结 3 423
故里飘歌
故里飘歌 2021-01-18 02:01

The challenge of attaching a GestureDetector to a ListPreference is 2-fold:

  1. Getting a handle to a ListPreference that\'s only defined in a preferences.xml (i.e
3条回答
  •  滥情空心
    2021-01-18 02:39

    As @TronicZomB suggested, this isn't directly possible.

    You can work around this by creating your own ListPreference derived class, getting its view in the inherited onBindDialogView().

    Remember however that the latter is tricky because onBindDialogView() is only called if onCreateDialogView() doesn't return null, and this can happen only if you create your own custom view for YourListPreference.

    The recommended way to do this is to build a custom Preference.

    Once you have done that, you have a reference to YourListPreference's view, which is mandatory for attaching GestureDetector because one of the steps requires setOnTouchListener() on the view.

提交回复
热议问题