当我点击登录按钮时,即使我创建新帐户,它也会显示烤面包信息用户名和密码不匹配。当我登录时,它应该显示新的活动,但这不起作用。我该如何解决这个问题?
MainActivity.java
package com.example.demir.carsharing;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.content.Intent;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
DatabaseHelper helper = new DatabaseHelper(this);
private Button v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onButtonClick(View v){
if (v.getId()==R.id.bLogin)
{
EditText a = (EditText)findViewById(R.id.TFUsername);
String str = a.getText().toString();
EditText b = (EditText)findViewById(R.id.TFPassword);
String pass = b.getText().toString();
String password = helper.searchPass(str);
if(pass.equals(password))
{
Intent i = new Intent(MainActivity.this, Display.class);
i.putExtra("uname", str);
startActivity(i);
}
else
{
// Display popup message
Toast temp =Toast.makeText(MainActivity.this, "Username and Password don't match", Toast.LENGTH_SHORT);
temp.show();
}
}
if (v.getId()==R.id.bSignUpHere)
{
Intent i = new Intent(MainActivity.this, signup.class);
startActivity(i);
}
}
}
Signup.java
package com.example.demir.carsharing;
import android.app.Activity;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
/**
* Created by Demir on 19.12.2016..
*/
public class signup extends Activity {
DatabaseHelper helper = new DatabaseHelper(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
}
public void onSignUpClick(View v)
{
if(v.getId() == R.id.bSignUpHere)
{
EditText name = (EditText)findViewById(R.id.TFName);
EditText email = (EditText)findViewById(R.id.TFEmail);
EditText uname = (EditText)findViewById(R.id.TFuname);
EditText pass1 = (EditText)findViewById(R.id.TFpass1);
EditText pass2 = (EditText)findViewById(R.id.TFpass2);
String namestr = name.getText().toString();
String emailstr = email.getText().toString();
String unamestr = uname.getText().toString();
String passstr1 = pass1.getText().toString();
String passstr2 = pass2.getText().toString();
if(!passstr1.equals(passstr2))
{
// DIsplay popup message
Toast pass =Toast.makeText(signup.this, "Password don't match", Toast.LENGTH_SHORT);
pass.show();
}
else {
//insert the detaild in database
Contact c = new Contact();
c.setName(namestr);
c.setEmail(emailstr);
c.setUname(unamestr);
c.setPass(passstr1);
helper.insertContact(c);
}
}
}
}
Display.java
package com.example.demir.carsharing;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
* Created by Demir on 19.12.2016..
*/
public class Display extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.display);
String username = getIntent().getStringExtra("Username");
TextView tv = (TextView)findViewById(R.id.TVUsername);
tv.setText(username);
}
}
答案 0 :(得分:0)
3with array 1