Skip to main content
se añadieron 1909 caracteres en el cuerpo
Origen Enlace
UserNameYo
  • 2.4k
  • 2
  • 19
  • 45

EDITO1:

public class Prueba extends AppCompatActivity implements SimpleGestureListener {

    TextView TextView1;
    GestosActivity detector;
    EditText editTextNombre;
    View view;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.prueba);

        // Oculta teclado al iniciar la Activity
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        editTextNombre = (EditText) findViewById(R.id.editTextNombre);
        TextView1 = (TextView) findViewById(R.id.TextView1);

        // gestos
        detector = new GestosActivity(this, this);


editTextNombre.setOnFocusChangeListener(new OnFocusChangeListener() {          
    public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
});

    }

    // gestos

    @Override
    public boolean dispatchTouchEvent(MotionEvent me) {
        this.detector.onTouchEvent(me);
        return super.dispatchTouchEvent(me);
    }

    @Override
    public void onSwipe(int direction) {
        switch (direction) {
            case GestosActivity.SWIPE_DOWN:
                Toast.makeText(this, "Sin función de momento", Toast.LENGTH_LONG).show();
                break;
            case GestosActivity.SWIPE_UP:
                Toast.makeText(this, "Sin función de momento", Toast.LENGTH_LONG).show();
                    }
                }
}

EDITO1:

public class Prueba extends AppCompatActivity implements SimpleGestureListener {

    TextView TextView1;
    GestosActivity detector;
    EditText editTextNombre;
    View view;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.prueba);

        // Oculta teclado al iniciar la Activity
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        editTextNombre = (EditText) findViewById(R.id.editTextNombre);
        TextView1 = (TextView) findViewById(R.id.TextView1);

        // gestos
        detector = new GestosActivity(this, this);


editTextNombre.setOnFocusChangeListener(new OnFocusChangeListener() {          
    public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
});

    }

    // gestos

    @Override
    public boolean dispatchTouchEvent(MotionEvent me) {
        this.detector.onTouchEvent(me);
        return super.dispatchTouchEvent(me);
    }

    @Override
    public void onSwipe(int direction) {
        switch (direction) {
            case GestosActivity.SWIPE_DOWN:
                Toast.makeText(this, "Sin función de momento", Toast.LENGTH_LONG).show();
                break;
            case GestosActivity.SWIPE_UP:
                Toast.makeText(this, "Sin función de momento", Toast.LENGTH_LONG).show();
                    }
                }
}
se añadieron 393 caracteres en el cuerpo
Origen Enlace
UserNameYo
  • 2.4k
  • 2
  • 19
  • 45

Lo único que de momento me ha funcionado es esto:

   // cierra teclado al hacer clic en TextView1
    TextView1.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
            return false;
        }
    });

Pero obviamente no es lo que busco, solamente se cierra al hacer clic en TextView1

Esto también me ha funcionado pero tengo que hacer doble clic para que se cierre el tecladosi lo hago encima de ScrollView:

Layout

 

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/base_añadir"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#f4f4f4">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="5dp"
            android:gravity="top|center"
            android:orientation="vertical">

            <EditText
                android:id="@+id/editTextNombre"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPersonName"
                android:text="Name" />

            <TextView
                android:id="@+id/TextView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView" />

        </LinearLayout>
    </ScrollView>
</AbsoluteLayout>

Lo único que de momento me ha funcionado es esto:

   // cierra teclado al hacer clic en TextView1
    TextView1.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
            return false;
        }
    });

Pero obviamente no es lo que busco, solamente se cierra al hacer clic en TextView1

Esto también me ha funcionado pero tengo que hacer doble clic para que se cierre el teclado:

Layout

 

<EditText
    android:id="@+id/editTextNombre"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Name" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="TextView" />

Esto me ha funcionado pero tengo que hacer doble clic si lo hago encima de ScrollView:

Layout

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/base_añadir"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#f4f4f4">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="5dp"
            android:gravity="top|center"
            android:orientation="vertical">

            <EditText
                android:id="@+id/editTextNombre"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="textPersonName"
                android:text="Name" />

            <TextView
                android:id="@+id/TextView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView" />

        </LinearLayout>
    </ScrollView>
</AbsoluteLayout>
se añadieron 393 caracteres en el cuerpo
Origen Enlace
UserNameYo
  • 2.4k
  • 2
  • 19
  • 45

Esto también me ha funcionado pero tengo que hacer doble clic para que se cierre el teclado:

@Override
public boolean onTouchEvent(MotionEvent event) {
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.
            INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    return true;
}

¿Alguien me puede ayudar?

¿Alguien me puede ayudar?

Esto también me ha funcionado pero tengo que hacer doble clic para que se cierre el teclado:

@Override
public boolean onTouchEvent(MotionEvent event) {
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.
            INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    return true;
}

¿Alguien me puede ayudar?

Origen Enlace
UserNameYo
  • 2.4k
  • 2
  • 19
  • 45
Loading