开发者

Android, show dialog when ListPreference item is clicked

Ba开发者_如何学Pythonsically I have a ListPreference to allow a user to change the X position of some text on my Live Wallpaper.

It contains 4 entries: top, middle, bottom and manually input X. The first 3 options are no problem, I simply get the SharedPreferences in my WallpaperService class and check if they are top, middle or bottom and change the position corresponding to their choice.

However, the last option is proving more difficult, what I want to do is have an EditText alert box popup when the user clicks the "Manually input X" ListPreference item so they can enter a value for X. I just cant figure out how to make the alert popup from clicking that specific List element.


You probably want to create a custom ListPreference. Basically you want to extend from ListPreference (see original here), and provide a custom protected void onPrepareDialogBuilder(Builder builder), in which you provide the additional "custom" list item and the onclick to handle the selection of the "custom" entry.

Note that I keep saying "custom" because it would be a best practice to make this class as reusable as possible.


Override onPreferenceTreeClick() in your PreferenceActivity and compare the preference it gives to the one you want to do something for.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜