Get Value of a Edit Text field

前端 未结 12 1037
既然无缘
既然无缘 2020-11-22 07:20

I am learning how to create UI elements. I have created a few EditText input fields. On the click of a Button I want to capture the content typed into that input field.

12条回答
  •  天涯浪人
    2020-11-22 08:05

    A more advanced way would be to use butterknife bindview. This eliminates redundant code.

    In your gradle under dependencies; add this 2 lines.

    compile('com.jakewharton:butterknife:8.5.1') {
            exclude module: 'support-compat'
        }
    apt 'com.jakewharton:butterknife-compiler:8.5.1'
    

    Then sync up. Example binding edittext in MainActivity

    import butterknife.BindView;   
    import butterknife.ButterKnife; 
    
    public class MainActivity {
    
    @BindView(R.id.name) EditTextView mName; 
    ...
    
       public void onCreate(Bundle savedInstanceState){
             ButterKnife.bind(this); 
             ...
       }
    
    }
    

    But this is an alternative once you feel more comfortable or starting to work with lots of data.

提交回复
热议问题