I am creating a login but it does not recognize me when I press the btnLogin button it does not create any action in the code the OnClickListener and the ErrorListener do not even appear enabled for me this is my Activity code I do not know what the problem could be I need help please
package com.example.elena5;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import java.util.HashMap;
import java.util.Map;
public class LoginActivity extends AppCompatActivity {
EditText Email, Pass;
Button Logear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//Inicializamos
Email = (EditText) findViewById(R.id.edtUsuario);
Pass = (EditText) findViewById(R.id.edtPassword);
Logear = (Button) findViewById(R.id.btnLogin);
Logear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ValidarEmail("http://192.168.1.4/index/Validarusuario.php");
}
});
}
private void ValidarEmail(String URL){
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>(){
@Override
public void onResponse(String response) {
if (!response.isEmpty()){
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra(MainActivity.nombres, Email.getText().toString());
startActivity(intent);
}else{
Toast.makeText(LoginActivity.this,"Usuario o Contraseña Incorrecta", Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error){
Toast.makeText(LoginActivity.this, "Usuario o Contraseña Incorrectas", Toast.LENGTH_SHORT).show();
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError{
Map<String, String> Parametros = new HashMap<String, String>();
Parametros.put("email",Email.getText().toString());
Parametros.put("password", Pass.getText().toString());
return Parametros;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
}
This is my XML code where my button is supposed to be all right and I'm calling it correctly I'm new to this so I don't understand what the detail in this action can be
<Button
android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="30dp"
android:layout_marginRight="15dp"
android:background="@color/design_default_color_secondary"
android:text="Iniciar Sesión"
android:textColor="#FFF"
android:textSize="18sp" />
The code does not have any errors, I am doing it with a local database.
After version 8 of android, for security reasons, it asks you to place the following line of code in the manifest and that's it.
android:usesCleartextTraffic="true"
And this solved my problem.