首页 \ 问答 \ EditText焦点自动打开键盘(EditText focus opens Keyboard automatically)

EditText焦点自动打开键盘(EditText focus opens Keyboard automatically)

当我开始登录活动。 它有两个字段的电子邮件和密码。 电子邮件应获得焦点,但在活动开始时不会自动打开键盘。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash_background_gradient" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginBottom="10dip"
        android:layout_marginTop="10dip"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/SplashLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="40dip"
            android:src="@drawable/splash_logo" />

        <EditText
            android:id="@+id/EmailAddress"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:hint="Email Address"
            android:maxLines="1" android:nextFocusRight="@+id/Password">


        </EditText>

        <EditText
            android:id="@+id/Password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="5dip"
            android:hint="Password"
            android:inputType="textPassword" />

        <Button
            android:id="@+id/Login"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="10dip"
            android:background="@drawable/login_button_selector"
            android:text="@string/login" />

        <TextView
            android:id="@+id/ForgotPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="28dp"
            android:layout_marginRight="28dp"
            android:layout_marginTop="10dip"
            android:text="@string/forgot_password"
            android:textColor="#000000"
            android:textSize="7pt"/>
    </LinearLayout>

</ScrollView>

When i start Login Activity. it has two fields email and password. Email should get the focus but not open the keyboard automatically when the activity starts.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/splash_background_gradient" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginBottom="10dip"
        android:layout_marginTop="10dip"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/SplashLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="40dip"
            android:src="@drawable/splash_logo" />

        <EditText
            android:id="@+id/EmailAddress"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:hint="Email Address"
            android:maxLines="1" android:nextFocusRight="@+id/Password">


        </EditText>

        <EditText
            android:id="@+id/Password"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="5dip"
            android:hint="Password"
            android:inputType="textPassword" />

        <Button
            android:id="@+id/Login"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="10dip"
            android:background="@drawable/login_button_selector"
            android:text="@string/login" />

        <TextView
            android:id="@+id/ForgotPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="28dp"
            android:layout_marginRight="28dp"
            android:layout_marginTop="10dip"
            android:text="@string/forgot_password"
            android:textColor="#000000"
            android:textSize="7pt"/>
    </LinearLayout>

</ScrollView>

原文:https://stackoverflow.com/questions/7934801
更新时间:2023-08-04 13:08

最满意答案

最可能的原因是没有任何东西保留这个对象,所以它被垃圾收集。 如果您创建一个对象并实现其finalize方法并在其中放置一个puts,您将能够看到这种情况。

尝试在创建工作表的控制器中跟踪您的状态,并将指针作为contextInfo传递给控制器​​。 如果此状态调解ui元素之间的并发交互,那么负责所有元素的控制器可能无论如何都需要跟踪它。 当然,可能更容易不传递contextInfo并使用哪个回调给表单跟踪它所调用的条件。


The most likely reason is that nothing is retaining this object so it gets garbage collected. If you create an object and implement its finalize method and put a puts in there, you will be able to see that this is the case.

Try tracking your state in the controller that is creating the sheet, and passing a pointer to the controller as the contextInfo. If this state is mediating concurrent interactions between ui elements, it is likely the controller that is responsible for all the elements needs to track it anyway. Of course, it is probably then easier to not pass a contextInfo and using which callback you give the sheet to keep track of what conditions it was called under.

相关问答

更多
  • 不,传递char**并不一定是安全的,其中void** (这实际上是void*[]函数参数实际上是预期的)。 编译器使您执行显式转换的事实是一个提示。 在实践中,它可能会很好。 但是,严格来说,对于不同类型的T和U ,您通常无法保证sizeof (T*) == sizeof (U*) 。 (例如,您可以想象一个假设的系统,其中sizeof (int*) < sizeof (char*)因为指针到int是对齐的,因此不需要存储最低有效位。)因此,您的swap函数可能使用错误的偏移索引到v数组。 另请参阅com ...
  • 我在MacRuby-devel邮件列表中获得了Watson的解决方案。 我应该编写我的代码: range=Pointer.new(NSRange.type) #though range=Pointer.new("{_NSRange=QQ}") would also work 然后,就像我以前一样 font=txtStor.attribute(NSFontAttributeName,atIndex:index,effectiveRange:range) 如果需要,我可以按range[0]取消引用范围。 ...
  • 最可能的原因是没有任何东西保留这个对象,所以它被垃圾收集。 如果您创建一个对象并实现其finalize方法并在其中放置一个puts,您将能够看到这种情况。 尝试在创建工作表的控制器中跟踪您的状态,并将指针作为contextInfo传递给控制器。 如果此状态调解ui元素之间的并发交互,那么负责所有元素的控制器可能无论如何都需要跟踪它。 当然,可能更容易不传递contextInfo并使用哪个回调给表单跟踪它所调用的条件。 The most likely reason is that nothing is ret ...
  • 鉴于指针指向“内部标识符”,我不认为你可以对存储在其中的实际值作出任何假设。 如果指针可以指向堆,那么您可能会看到一组可能的值,并且它将在未来微妙(或明显)中断。 为什么不只是创建PolygonType* - > index的一次性反向映射并使用它? Given that the pointer is pointing to an "internal identifier" I don't think you can make any assumptions about the actual values ...
  • 你将*f=emptylines放在函数的开头void test2(int *f); 然后你计算emptylines但这不会影响f指向的值。 您需要将该赋值*f=emptylines移至该函数的末尾,在返回之前和计算出emptylines void test2(int *f){ // stuff to calculate emptylines .... *f=emptylines; // at the end } You are putting *f=emptylines in t ...
  • 你的showChar和showInt函数正在打印不同的东西。 在showChar ,这个: cout << &name << endl; 打印name的地址,这是一个局部变量 。 在showInt ,您不打印&num ;的值。 而是打印num的值 ,这是一个地址,但不是局部变量的地址。 在showChar ,如果要打印name值作为地址 ,则需要将其转换为其他指针类型,例如void* : cout << (void*)name << endl; 因为operator<< for char*的重载取消引用 ...
  • 问题是指针算术。 当你拿一个指针并减去1时,你实际上是减去(1*sizeof(struct)) 。 第一个带有“-sizeof”的等式,你实际上是从指针中减去(sizeof(struct) * sizeof(struct))字节。 合理? The problem is pointer arithmetic. When you take a pointer and subtract 1, you are really subtracting (1*sizeof(struct)). The first equa ...
  • 只要您小心保持您的呼叫类型正确,这是完成您描述的相当C语言的方式。 As long as you are careful to keep your calls type-correct, this is a fairly C-idiomatic way to accomplish what you describe.
  • 列出的前四个函数定义了要写入的对象的类型。 所以内部函数可能如下所示: void eeprom_update_float (float *addr, float value) { *addr = value; } 这通过确保目标指针与源变量相同来提供类型安全性好处(例如,不能将float写入uint16_t )。 最终版本void eeprom_update_block()只是将任意内存块写入给定地址。 它可能使用类似memcpy东西: void eeprom_update_block (cons ...
  • 您可以删除以下类型: class Token { using Deleter = void(void*); using Func = void(*)(void*); template static void proto(void *ptr) { T t = static_cast(ptr); // do whatever you want here... // ... or use specia ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。