I'm new to android, I wrote a code for myself, when the button is pressed, it switches to another activity, but I want to connect it to the password and user name.
if "username && password" is correct then switch to activity 2. how can I do it?
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Giris_activity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_giris);
button = (Button) findViewById(R.id.giris);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
openbaslangic();
}
});
}
public void openbaslangic()
{
Intent intent = new Intent(this, Baslangic_activity.class);
startActivity(intent);
finish();
}
}```
CodePudding user response:
you must also find text fields(username and password)
EditText username = (EditText) findViewById(R.id.username);
EditText password= (EditText) findViewById(R.id.password);
after that you must check validation both field with Your desired values in
openbaslangic()
like this
if(username.getText().toString() == "your desired username" && password.getText().toString() == "your desired password"){
Intent intent = new Intent(this, Baslangic_activity.class);
startActivity(intent);
finish();
}