Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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 :: rotate vector 3d java 
Java :: java cambiar formato de fecha 
Java :: exponet 
Java :: java gui bank account program 
Java :: Printing Hexadecimal Code 
Java :: worldedit api copy schematic 
Java :: Longest decreasing subsequence in java 
Java :: Java program to print Student Info by using Class, Object, Method. 
Java :: how to create arraylist in java 
Java :: prime numbers most efficient algorithm java 
Java :: open google maps cycling navigation intent 
Java :: What is Java? 
Java :: jframe centerlaized 
Java :: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 
Java :: how to add a singleton hashset in java 
Java :: Iterating an Array Using While Loop 
Java :: mincraft command in plugin 
Java :: gradle project load test data json file with jackson 
Java :: Was ist ein String in java 
Java :: android diagonal gradle 
Java :: fly dfguyghj: Javascript 
Java :: [ERROR] Error executing Maven. java.io.FileNotFoundException: The specified user settings file does not exist: /usr/lib/jvm/java-1.8.0-openjdk-amd64 
Java :: android studio epoch to localdatetime 
Java :: Java Method Overloading by changing the data type of parameters 
Java :: jdbc outside of ide 
Java :: lauch app from brodcast reciever 
Java :: the built-in base class in java, which is used to handle all exceptions is 
Java :: android notification addaction example 
Java :: java create a random number 
Java :: View get text android Close 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =