Нет ответа от Button и AlertDialog

Я пытаюсь подключить приложение моего проекта к онлайн-базе данных через хостинг cPanel. Я использовал AlertDialog.Builder, setOnClickListener, Try and Catch в Android Studio, но он не работает. Я использую это для моей страницы входа. Кнопка входа не будет перенаправлять меня на домашнюю страницу. Диалог предупреждения тоже не появится.

Вот мой Java-файл для страницы входа,

package daffaalmer.bloom2nd;

import android.app.AlertDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.Volley;

import org.json.JSONException;
import org.json.JSONObject;

public class Login extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

final EditText EditTextEmail = (EditText)
findViewById(R.id.EditTextEmail);
final EditText EditTextPassword = (EditText)
findViewById(R.id.EditTextPassword);
final Button ButtonLogin = (Button) findViewById(R.id.ButtonLogin);
final TextView TextViewRegister = (TextView)
findViewById(R.id.TextViewRegister);

TextViewRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent registerIntent = new Intent(Login.this, Register.class);
Login.this.startActivity(registerIntent);
}
});

ButtonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String email = EditTextEmail.getText().toString();
final String password = EditTextPassword.getText().toString();

Response.Listener<String> responseListener = new
Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success =
jsonResponse.getBoolean("success");

if (success) {
String name = jsonResponse.getString("name");
String email = jsonResponse.getString("email");

Intent loginIntent = new Intent(Login.this,
Home.class);
loginIntent.putExtra("name", name);
loginIntent.putExtra("email", email);
Login.this.startActivity(loginIntent);

} else {
AlertDialog.Builder builder = new
AlertDialog.Builder(Login.this);
builder.setMessage("Login Failed")
.setNegativeButton("Retry", null)
.create()
.show();

}
} catch (JSONException e) {
e.printStackTrace();
}

}
};

LoginRequest loginRequest = new LoginRequest(email, password,
responseListener);
RequestQueue queue = Volley.newRequestQueue(Login.this);
queue.add(loginRequest);

}
});
}
}

Вот мой XML-файл для страницы входа,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/colorPrimaryDark"android:paddingBottom="64dp"android:paddingLeft="50dp"android:paddingRight="50dp"android:paddingTop="64dp"tools:context="daffaalmer.bloom2nd.Login">

<LinearLayout
android:layout_width="wrap_content"android:layout_height="match_parent"android:orientation="vertical"android:weightSum="1"android:layout_alignParentTop="true"android:layout_alignParentLeft="true"android:layout_alignParentStart="true"android:layout_marginTop="30dp">

<ImageView
android:id="@+id/BloomLogo"android:layout_width="match_parent"android:layout_height="150dp"app:srcCompat="@drawable/logo"android:layout_weight="0.26" />

<ImageView
android:id="@+id/WelcomeWriting"android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingLeft="10dp"android:paddingRight="10dp"app:srcCompat="@drawable/writing" />

<EditText
android:id="@+id/EditTextEmail"style="@style/edit_text_style"android:hint="E-mail Address"android:inputType="textEmailAddress" />

<EditText
android:id="@+id/EditTextPassword"style="@style/edit_text_style"android:hint="Password"android:inputType="textPassword" />

<Button
android:id="@+id/ButtonLogin"style="@style/button_style"android:text="LOG IN" />

<TextView
android:id="@+id/TextViewRegister"style="@style/textView_style"android:text="Not a member yet? Sign Up"android:textAppearance="@android:style/TextAppearance.Medium" />
</LinearLayout>

</RelativeLayout>

Вот мой Java-файл для LoginRequest,

package daffaalmer.bloom2nd;

import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.HashMap;
import java.util.Map;

public class LoginRequest extends StringRequest {

private static final String LOGIN_REQUEST_URL =
"daffaalmerf.5gbfree.com/Login.php";
private Map<String, String> params;

public LoginRequest(String email, String password, Response.Listener<String>
listener){
super(Method.POST, LOGIN_REQUEST_URL, listener, null );
params = new HashMap<>();
params.put("email", email);
params.put("password", password);

}

@Override
public Map<String, String> getParams() {return params;}

}

И вот мой файл Login.php в базе данных

<?php
$con = mysqli_connect("daffaalmerf.5gbfree.com", "daffaalm_almer",
"daffaalm2849", "daffaalm_pribadi_data");

$email = $_POST["email"];
$password = $_POST["password"];

$statement = mysqli_prepare($con, "SELECT * FROM pribadi_data WHERE email =
? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $email, $password);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $name, $dateofbirth, $address,
$phonenumber, $email, $password);

$response = array();
$response["success"] = false;

while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["name"] = $name;
$response["dateofbirth"] = $dateofbirth;
$response["address"] = $address;
$response["phonenumber"] = $phonenumber;
$response["email"] = $email;
$response["password"] = $password;
}

echo json_encode($response);

?>

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector