Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android dismiss keyboard

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Comment

close keyboard android

public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = 
        (InputMethodManager) activity.getSystemService(
            Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(
        activity.getCurrentFocus().getWindowToken(), 0);
}
Comment

android java close keyboard

package org.geeksforgeeks.gfgHideKey
  
    import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod
    .InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;
  
public class MainActivity
    extends AppCompatActivity {
    private TextView textViewResult;
    private EditText editTextInput;
  
    @Override
    protected void onCreate(
        Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
  
        textViewResult
            = findViewById(
                R.id.text_view_result);
        editTextInput
            = findViewById(
                R.id.edit_text_input);
    }
  
    public void setText(View v)
    {
        String newText
            = editTextInput
                  .getText()
                  .toString();
        textViewResult.setText(newText);
  
        closeKeyboard();
        editTextInput.setText("");
    }
  
    private void closeKeyboard()
    {
        // this will give us the view
        // which is currently focus
        // in this layout
        View view = this.getCurrentFocus();
  
        // if nothing is currently
        // focus then this will protect
        // the app from crash
        if (view != null) {
  
            // now assign the system
            // service to InputMethodManager
            InputMethodManager manager
                = (InputMethodManager)
                    getSystemService(
                        Context.INPUT_METHOD_SERVICE);
            manager
                .hideSoftInputFromWindow(
                    view.getWindowToken(), 0);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: jbutton border size java 
Java :: printing multiple variables in java 
Java :: java instance of a class 
Java :: spring filter exception handling 
Java :: java wait for user input 
Java :: java get month 
Java :: find java_home path in cmd 
Java :: insert string in string java 
Java :: how to go to next iteration of while loop java 
Java :: java basic syntax 
Java :: mockito verify more than once 
Java :: java append a string to file 
Java :: java mail use tls 1.2 
Java :: json array to list in java 
Java :: java fot 
Java :: distance point to line java 
Java :: kubectl config kubernetes dashboard 
Java :: System.out.println("Hello world") 
Java :: how to initialize an empty array in java 
Java :: hash table implementation java 
Java :: java stream and filter 
Java :: export JAVA_HOME=` mac 
Java :: how to change java version in pom.xml 
Java :: bubble sort in java 
Java :: spring-boot java header appliacation/json constant 
Java :: java pattern check 
Java :: get index of element in array java 
Java :: java arraylist with double 
Java :: set matrix zeros programming creek 
Java :: java abstraction 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =