简体   繁体   English

如何在Android中使editText专注于按钮单击?

[英]How to make editText focusable on button click in Android?

on onCreate method i am making all editText disable by using setFocusable method. 在onCreate方法上,我正在使用setFocusable方法禁用所有editText。 But on button click i want to set focus again. 但是在按钮上单击我要再次设置焦点。 I have implemented this , but now working. 我已经实现了,但是现在可以工作了。

 protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.contactform);

            name = (EditText) findViewById(R.id.name);
            email = (EditText) findViewById(R.id.email);
            address = (EditText) findViewById(R.id.address);
            phone_number = (EditText) findViewById(R.id.phone_number);

           name.setFocusable(false);
           address.setFocusable(false);
           phone_number.setFocusable(false);
           email.setFocusable(false);

    }


    public boolean onOptionsItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            switch(item.getItemId()){

            case R.id.editButton:
                  Toast.makeText(this, "clicked", Toast.LENGTH_LONG).show();
                    name.setFocusable(true);
                    name.setFocusable(true);
                    address.setFocusable(true);
                    phone_number.setFocusable(true);
                    email.setFocusable(true);

                break;
            }
            return super.onOptionsItemSelected(item);

        }

Use : 采用 :

setFocusable(true)
setFocusableInTouchMode(true)

Instead : 相反:

setEnabled(true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果未正确完成,如何使EditText IME“下一步”按钮不进入下一个可聚焦的EditText - How can I make the EditText IME “Next” button not take to the next focusable EditText, if not completed correctly 滑动菜单未显示时如何使EditText不能聚焦-Android - How to make EditText non-focusable when Sliding menu is not out - Android 如何使一个按钮可以在RecyclerView中的项目中聚焦 - How to make a button focusable in an item in RecyclerView 如何在Android中隐藏editText上的按钮? - How to hide a button on editText click in Android? Android按钮 - 如何将focusable设置为true并在第一次单击时仍接受onClick侦听器? - Android button - How to set focusable to true and still accept onClick listener on first click? 像在iOS中那样如何在带有Button的Android EditText中进行制作? - How to make in Android EditText with Button like in iOS? Android:SetOnclickListener用于android:focusable =“ false”的EditText - Android: SetOnclickListener for a EditText which is android:focusable=“false” 有没有办法通过禁用的 focusableInTouchMode 使 EditText 成为焦点? - Is there a way to make EditText focusable with disabled focusableInTouchMode? 如何使FrameLayout具有可聚焦性? - How to make FrameLayout focusable? Android EditText.setError无法在无法聚焦的情况下工作 - Android EditText.setError not working in not focusable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM