不能设法requestFocus的一个微调 [英] Can't manage to requestFocus a Spinner
问题描述
我有一个屏幕一个恼人的问题。该屏幕由下其他一堆纱厂之一,然后下面的微调,一个EditText。
I've got an annoying issue with a screen. The screen consists of a bunch of Spinners one under the other, and then underneath the spinner, an EditText.
的问题是,在屏幕开始时,的EditText具有焦点,这意味着有些纱厂偏离屏幕的顶部。尝试,因为我可能,我不能让顶部微调开始集中,通过使用<不是requestFocus />
屏幕XML,或使用不是requestFocus()
在code。我一直试图做什么 requestFocus的问题暗示,如果我是正确的下面的建议,这不是'科技工作无论是。
The problem is that when the screen starts, the EditText has focus, meaning that some Spinners are off the top of the screen. Try as I might, I cannot make the top Spinner start focused, either by using <requestFocus/>
in the screen XML, or by using requestFocus()
in code. I've attempted to do what requestFocus problem suggests, and if I'm following the suggestion correctly, it doesn't work either.
要重现该问题,在Eclipse中创建一个新的Android项目。 main.xml中为
To reproduce the issue, create a new Android project in Eclipse. main.xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Spinner
android:id="@+id/spinner"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<requestFocus />
</Spinner>
<EditText
android:id="@+id/edittext"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
活动code是
The activity code is
package nz.co.kb.testspinner;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class TestSpinner extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
View view = getLayoutInflater().inflate(R.layout.main, null);
final View spinner = view.findViewById(R.id.spinner);
view.post(new Runnable() {
public void run() {
spinner.requestFocus();
}
});
setContentView(view);
spinner.requestFocus();
}
}
请注意多种风格requestFocus的企图。
Note multiple styles of requestFocus attempted.
这是一个平台的bug,还是我做错了什么?
Is this a platform bug, or am I doing something wrong?
感谢。
推荐答案
从网上的文档:
一个视图将不会采取实际关注,如果它不是可聚焦(isFocusable()返回false),或者如果它是可聚焦的,这不可作为焦点,联系方式(isFocusableInTouchMode()),而该设备在触摸模式。
A view will not actually take focus if it is not focusable (isFocusable() returns false), or if it is focusable and it is not focusable in touch mode (isFocusableInTouchMode()) while the device is in touch mode.
这篇关于不能设法requestFocus的一个微调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!