我想轉到下一頁(mainActivity)。我能夠註冊並將這些信息發送到數據庫。但只有成功消息和確定按鈕出來。錯誤沒有出來。請檢查我的代碼。不能轉到下一頁
LogingActivity.java
package com.life.registeration;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
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.JSONObject;
public class LoginActivity extends AppCompatActivity {
private AlertDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
TextView registerButton = (TextView) findViewById(R.id.registerButton);
registerButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
});
final EditText idText = (EditText) findViewById(R.id.idText);
final EditText passwordText = (EditText) findViewById(R.id.passwordText);
final Button loginButton = (Button) findViewById(R.id.loginButton);
loginButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
String userID = idText.getText().toString();
String userPassword = passwordText.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){
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
dialog = builder.setMessage("Login success.")
.setPositiveButton("ok", null)
.create();
dialog.show();
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
LoginActivity.this.startActivity(intent);
finish();
}
else{
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
dialog = builder.setMessage("please, check your id.")
.setNegativeButton("re try", null)
.create();
dialog.show();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(userID, userPassword, responseListener);
RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
queue.add(loginRequest);
}
});
}
@Override
protected void onStop(){
super.onStop();
if(dialog != null){
dialog.dismiss();
dialog = null;
}
}
}
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.life.registeration">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".RegisterActivity" /><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
那麼問題到底在哪裏?點擊登錄按鈕或註冊按鈕> – OBX
@OBX當登錄成功時,顯示成功,並且不會進入下一頁。 –
註冊按鈕怎麼樣?當你點擊它時你能開展下一個活動嗎? – OBX