Android的微调关闭Android

由网友(堅持到底)分享简介:我有一个微调的活动,我想知道是否有可能以编程方式关闭微调,如果用户打开它。I have an activity with a spinner, and I was wondering if it is possible to close the spinner programmatically, if the use...

我有一个微调的活动,我想知道是否有可能以编程方式关闭微调,如果用户打开它。

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.

整个故事是在后台我运行在一个单独的线程的过程。当该过程完成后,我上调用主活性的处理程序,并根据结果,我执行某些任务。它是那么我想关闭微调,但用户已经打开了它。

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);
    }
}

干杯!

推荐答案

我不明白的方式来实现这一目标 - 有关于微调没有方法来关闭它。的微调是一个 AlertDialog 在Android 1.x和2.x,和我的开放式的一部分米不完全确定它是如何在蜂窝使用全息主题时实施。

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.

唯一的解决方法是将克隆的源微调,并添加了一些code自己关闭对话框。但是,再次,它不会对蜂窝或更高,直到你可以看到和克隆工作的是的code为好。

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.

除此之外,我会认为你想要的是差UX。如果用户打开了微调,他们最有可能积极研究微调的内容并作出选择。唬弄了这一点从他们的手指将它们混淆,最好的。请考虑一个替代方法。

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()。你并不需要,甚至想 getApplicationContext()创建时 ArrayAdapter

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.

阅读全文

相关推荐

最新文章