Android 微调器关闭 [英] Android spinner close

查看:28
本文介绍了Android 微调器关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有微调器的活动,我想知道是否可以通过编程方式关闭微调器(如果用户已打开它).

I have an activity with a spinner, and I was wondering if it is possible to close the spinner programmatically, if the user has opened it.

整个故事是在后台我在一个单独的线程上运行一个进程.流程完成后,我会在主要活动上调用 Handler,然后根据结果执行一些任务.然后我想关闭微调器,用户已经打开它.

The whole story is that in the background I am running a process on a separate thread. When the process has finished, I invoke a Handler on the main activity and, depending on the outcome, I perform some tasks. It is then that I want to close the spinner, it the user has opened it.

微调器位于 main.xml 布局中:

The spinner is in the main.xml layout:

<Spinner android:id="@+id/birthPlaceSpinner" android:layout_weight="1" 
android:layout_height="wrap_content" android:prompt="@string/select"
android:layout_width="fill_parent" />

这是处理程序:

private class BirthplaceChangedHandler extends Handler {

    @Override
    public void handleMessage(Message msg) {
        String placeFilterStr = birthPlaceFilterText.getText().toString();
        if ("".equals(placeFilterStr) || placeFilterStr == null || validNewAddresses.isEmpty()) {
            birthPlaceSpinner.setEnabled(false);
            hideGeoLocationInformation();
        } else {
            birthPlaceSpinner.setEnabled(true);
        }
        adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.multiline_spinner_dropdown_item, validNewAddressesStr)
        birthPlaceSpinner.setAdapter(adapter);
    }
}

干杯!

推荐答案

我看不出有什么方法可以实现——Spinner 上没有关闭它的方法.Spinner 的开放"部分是 Android 1.x 和 2.x 上的 AlertDialog,我不完全确定它在使用时如何在 Honeycomb 上实现全息主题.

I don't see a way to accomplish that -- there is no method on Spinner to close it. The "open" part of a Spinner is an AlertDialog on Android 1.x and 2.x, and I'm not completely sure how it is implemented on Honeycomb when using the holographic theme.

唯一的解决方法是克隆 Spinner 的源代码并自己添加一些代码以关闭对话框.但是,在您也可以查看和克隆代码之前,它也无法在 Honeycomb 或更高版本上运行.

The only workaround would be to clone the source for Spinner and add in some code yourself to dismiss the dialog. But, again, it would not work on Honeycomb or higher until you can see and clone that code as well.

除此之外,我认为您想要的是糟糕的用户体验.如果用户打开 Spinner,他们很可能正在积极检查 Spinner 的内容并进行选择.从他们的手指下拉出来最多只会让他们感到困惑.请考虑另一种方法.

Beyond that, I would think that what you want is poor UX. If the user opened the Spinner, they are most likely actively examining the Spinner's contents and making a selection. Yanking that out from under their finger will confuse them, at best. Please consider an alternative approach.

此外,不要使用 getApplicationContext(),除非您知道为什么使用 getApplicationContext().在创建 ArrayAdapter 时,您不需要甚至不需要 getApplicationContext().

Also, don't use getApplicationContext() unless you know why you are using getApplicationContext(). You do not need or even want getApplicationContext() when creating an ArrayAdapter.

这篇关于Android 微调器关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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