我可以强制微调的下拉认为留可见取向的变化? [英] Can I force the dropdown view of a spinner to stay visible on orientation changes?

查看:149
本文介绍了我可以强制微调的下拉认为留可见取向的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否是从标题清楚我问,所以这里有一些步骤来重现(假设你有一个微调的布局):

I don't know if it's clear from the title what I asked, so here are some steps to reproduce (assuming you have a layout with a spinner):


  1. 打开微调>下拉列表中点击。

  2. 从纵向到横向(反之亦然)>列表被关闭旋转设备。

我的问题是,我想保持旋转设备后打开列表。我知道,这通常是可能的,如果重写 onConfigurationChanged ,但我已经定义为横向模式不同的布局,所以在我onConfigurationChanged方法,我必须调用的setContentView 并设置适配器对于景观微调,从而关闭了在纵向模式下打开的下拉菜单视图。

My problem is that I would like to keep the list opened after rotating the device. I know that this is usually possible if overriding onConfigurationChanged, but I have defined a different layout for landscape mode, so in my onConfigurationChanged method I have to call setContentView and set the adapter for the landscape spinner, which closes the dropdown view that was opened in portrait mode.

有没有一种方法,我可以从关闭或者迫使其旋转设备后展现prevent的下拉列表?

Is there a way I could prevent the dropdown list from closing or perhaps forcing it to show after rotating the device?

推荐答案

我发现了一个非常难看的解决这个(以下简称行动发生在地方的 onConfigurationChanged 法):

I found a very ugly solution to this (the 'action' takes place in the onConfigurationChanged method):


  1. 在调用的setContentView ,检查是否显示的下拉菜单视图的(*)如果是这样,保存当前的微调选择的位置( INT POS = spinner.getSelectedItemPosition())。

  1. Before calling setContentView, check if the dropdown view is shown (*) and if so, save the position that is currently selected in the spinner (int pos = spinner.getSelectedItemPosition()).

在调用后的的setContentView 并设置微调适配器,如果下拉视图在步骤1中,强制下拉列表视图通过调用显示的 performClick 的微调:

After calling setContentView and setting the spinner adapter, if the dropdown view was shown in step 1, force the dropdown view to show by calling performClick on the spinner:

spinner.setSelection(pos);// this way we make sure that the same item
                          // remains selected after rotating the device
spinner.performClick(); //show the dropdown view 


(*)检查是否已显示的下拉视图是棘手的部分。我还没有发现(还),让我知道了下拉列表视图是否显示,所以我不得不做以下的方法:

(*) Checking if the dropdown view is shown is the trickier part. I haven't found (yet) a method that lets me know whether the dropdown view is shown, so I had to do the following:


  • 按住微调的pressed状态布尔变量(命名,例如, isClicked )。

设置的 onTouchListener 作为微调,并在 onTouch 方式将 isClicked 以真(攻微调时,dropdwon视图中打开,所以 isClicked ==真表示下拉图如图)。

Set an onTouchListener for the spinner and in the onTouch method set isClicked to true (when tapping the spinner, the dropdwon view opens, so isClicked == true means that the dropdown view is shown).

覆盖的onkeydown 的onkeyup 并在后退按钮是pressed,如果 isClicked 为真,将其设置为false (我假定pressing回来的 isClicked ==真表示关闭下拉列表视图)。

Override onKeyDown or onKeyUp and when back button is pressed, if isClicked is true, set it to false (I assumed that pressing back with isClicked==true means closing the dropdown view).

使用的值 isClicked onConfigurationChanged 方法来检查是否显示的下拉视图。

Use the value of isClicked in onConfigurationChanged method to check if the dropdown view is shown.

就像我说的,这是一个丑陋的修复,但它是唯一一个我能想出直到现在。如果有人有其他想法,请张贴。

Like I said, it's an ugly fix, but it's the only one I could come up with until now. If anybody has other ideas, please post them.

这篇关于我可以强制微调的下拉认为留可见取向的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆