onClickListener button problem comparing string [duplicate]












0
















This question already has an answer here:




  • Java Does Not Equal (!=) Not Working? [duplicate]

    7 answers



  • How do I compare strings in Java?

    23 answers



  • Android Studio .compareTo and .equals with strings not working

    6 answers




Good morning, I have a problem with a button. What you're supposed to do is to click on it and compare the string I'm passing and if it's the same as the one I've told you to launch the Intent.



public class SegundoActivity extends AppCompatActivity {
String palabra;
EditText letraI,letraH,letraL,letraD,letraO,letraR;
Button probar;
TextView textView8;
final String palabrafin = "IHLDOR";

private static final String TAG = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_segundo);
letraI = (EditText) findViewById(R.id.letraI);
letraH = (EditText) findViewById(R.id.letraH);
letraL = (EditText) findViewById(R.id.letraL);
letraD = (EditText) findViewById(R.id.letraD);
letraO = (EditText) findViewById(R.id.letraO);
letraR = (EditText) findViewById(R.id.letraR);
textView8 = (TextView) findViewById(R.id.textView8);
probar = (Button) findViewById(R.id.button);

String palabra1 = letraI.getText().toString().toUpperCase();
String palabra2 = letraH.getText().toString().toUpperCase();
String palabra3 = letraL.getText().toString().toUpperCase();
String palabra4 = letraD.getText().toString().toUpperCase();
String palabra5 = letraO.getText().toString().toUpperCase();
String palabra6 = letraR.getText().toString().toUpperCase();

palabra = palabra1+palabra2+palabra3+palabra4+palabra5+palabra6;

probar.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
textView8.setText(palabra);
compare();
}

});
}

private void compare() {
if (palabra!=palabrafin) {
Toast.makeText(SegundoActivity.this,"Contrase invalida " + palabra,Toast.LENGTH_LONG).show();
}else{
Intent intent = new Intent(SegundoActivity.this, TercerActivity.class);
startActivity(intent);
}

}


}


If the word palabra its equals to the word palabrafin to launch the intent.If its not the same to launch the toast.










share|improve this question













marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 13:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Change it to if (!palabra.equals(palabrafin)) ....

    – Mike M.
    Nov 25 '18 at 13:47











  • Ok i did it but now if i put a diferent word of palabrafin also do the intent

    – Peter
    Nov 25 '18 at 13:52











  • Move all of the String palabra* = ... lines, and the palabra = ... line to inside onClick(), before the compare() call.

    – Mike M.
    Nov 25 '18 at 13:55













  • Yes that was the solution! Thnaks Mike i didnt realize.

    – Peter
    Nov 25 '18 at 13:56











  • No problem. Sorry I didn't catch that to begin with. I'll update the duplicate list with an appropriate link. Glad you got it working. Cheers!

    – Mike M.
    Nov 25 '18 at 13:59


















0
















This question already has an answer here:




  • Java Does Not Equal (!=) Not Working? [duplicate]

    7 answers



  • How do I compare strings in Java?

    23 answers



  • Android Studio .compareTo and .equals with strings not working

    6 answers




Good morning, I have a problem with a button. What you're supposed to do is to click on it and compare the string I'm passing and if it's the same as the one I've told you to launch the Intent.



public class SegundoActivity extends AppCompatActivity {
String palabra;
EditText letraI,letraH,letraL,letraD,letraO,letraR;
Button probar;
TextView textView8;
final String palabrafin = "IHLDOR";

private static final String TAG = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_segundo);
letraI = (EditText) findViewById(R.id.letraI);
letraH = (EditText) findViewById(R.id.letraH);
letraL = (EditText) findViewById(R.id.letraL);
letraD = (EditText) findViewById(R.id.letraD);
letraO = (EditText) findViewById(R.id.letraO);
letraR = (EditText) findViewById(R.id.letraR);
textView8 = (TextView) findViewById(R.id.textView8);
probar = (Button) findViewById(R.id.button);

String palabra1 = letraI.getText().toString().toUpperCase();
String palabra2 = letraH.getText().toString().toUpperCase();
String palabra3 = letraL.getText().toString().toUpperCase();
String palabra4 = letraD.getText().toString().toUpperCase();
String palabra5 = letraO.getText().toString().toUpperCase();
String palabra6 = letraR.getText().toString().toUpperCase();

palabra = palabra1+palabra2+palabra3+palabra4+palabra5+palabra6;

probar.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
textView8.setText(palabra);
compare();
}

});
}

private void compare() {
if (palabra!=palabrafin) {
Toast.makeText(SegundoActivity.this,"Contrase invalida " + palabra,Toast.LENGTH_LONG).show();
}else{
Intent intent = new Intent(SegundoActivity.this, TercerActivity.class);
startActivity(intent);
}

}


}


If the word palabra its equals to the word palabrafin to launch the intent.If its not the same to launch the toast.










share|improve this question













marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 13:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • Change it to if (!palabra.equals(palabrafin)) ....

    – Mike M.
    Nov 25 '18 at 13:47











  • Ok i did it but now if i put a diferent word of palabrafin also do the intent

    – Peter
    Nov 25 '18 at 13:52











  • Move all of the String palabra* = ... lines, and the palabra = ... line to inside onClick(), before the compare() call.

    – Mike M.
    Nov 25 '18 at 13:55













  • Yes that was the solution! Thnaks Mike i didnt realize.

    – Peter
    Nov 25 '18 at 13:56











  • No problem. Sorry I didn't catch that to begin with. I'll update the duplicate list with an appropriate link. Glad you got it working. Cheers!

    – Mike M.
    Nov 25 '18 at 13:59
















0












0








0


1







This question already has an answer here:




  • Java Does Not Equal (!=) Not Working? [duplicate]

    7 answers



  • How do I compare strings in Java?

    23 answers



  • Android Studio .compareTo and .equals with strings not working

    6 answers




Good morning, I have a problem with a button. What you're supposed to do is to click on it and compare the string I'm passing and if it's the same as the one I've told you to launch the Intent.



public class SegundoActivity extends AppCompatActivity {
String palabra;
EditText letraI,letraH,letraL,letraD,letraO,letraR;
Button probar;
TextView textView8;
final String palabrafin = "IHLDOR";

private static final String TAG = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_segundo);
letraI = (EditText) findViewById(R.id.letraI);
letraH = (EditText) findViewById(R.id.letraH);
letraL = (EditText) findViewById(R.id.letraL);
letraD = (EditText) findViewById(R.id.letraD);
letraO = (EditText) findViewById(R.id.letraO);
letraR = (EditText) findViewById(R.id.letraR);
textView8 = (TextView) findViewById(R.id.textView8);
probar = (Button) findViewById(R.id.button);

String palabra1 = letraI.getText().toString().toUpperCase();
String palabra2 = letraH.getText().toString().toUpperCase();
String palabra3 = letraL.getText().toString().toUpperCase();
String palabra4 = letraD.getText().toString().toUpperCase();
String palabra5 = letraO.getText().toString().toUpperCase();
String palabra6 = letraR.getText().toString().toUpperCase();

palabra = palabra1+palabra2+palabra3+palabra4+palabra5+palabra6;

probar.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
textView8.setText(palabra);
compare();
}

});
}

private void compare() {
if (palabra!=palabrafin) {
Toast.makeText(SegundoActivity.this,"Contrase invalida " + palabra,Toast.LENGTH_LONG).show();
}else{
Intent intent = new Intent(SegundoActivity.this, TercerActivity.class);
startActivity(intent);
}

}


}


If the word palabra its equals to the word palabrafin to launch the intent.If its not the same to launch the toast.










share|improve this question















This question already has an answer here:




  • Java Does Not Equal (!=) Not Working? [duplicate]

    7 answers



  • How do I compare strings in Java?

    23 answers



  • Android Studio .compareTo and .equals with strings not working

    6 answers




Good morning, I have a problem with a button. What you're supposed to do is to click on it and compare the string I'm passing and if it's the same as the one I've told you to launch the Intent.



public class SegundoActivity extends AppCompatActivity {
String palabra;
EditText letraI,letraH,letraL,letraD,letraO,letraR;
Button probar;
TextView textView8;
final String palabrafin = "IHLDOR";

private static final String TAG = "";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_segundo);
letraI = (EditText) findViewById(R.id.letraI);
letraH = (EditText) findViewById(R.id.letraH);
letraL = (EditText) findViewById(R.id.letraL);
letraD = (EditText) findViewById(R.id.letraD);
letraO = (EditText) findViewById(R.id.letraO);
letraR = (EditText) findViewById(R.id.letraR);
textView8 = (TextView) findViewById(R.id.textView8);
probar = (Button) findViewById(R.id.button);

String palabra1 = letraI.getText().toString().toUpperCase();
String palabra2 = letraH.getText().toString().toUpperCase();
String palabra3 = letraL.getText().toString().toUpperCase();
String palabra4 = letraD.getText().toString().toUpperCase();
String palabra5 = letraO.getText().toString().toUpperCase();
String palabra6 = letraR.getText().toString().toUpperCase();

palabra = palabra1+palabra2+palabra3+palabra4+palabra5+palabra6;

probar.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
textView8.setText(palabra);
compare();
}

});
}

private void compare() {
if (palabra!=palabrafin) {
Toast.makeText(SegundoActivity.this,"Contrase invalida " + palabra,Toast.LENGTH_LONG).show();
}else{
Intent intent = new Intent(SegundoActivity.this, TercerActivity.class);
startActivity(intent);
}

}


}


If the word palabra its equals to the word palabrafin to launch the intent.If its not the same to launch the toast.





This question already has an answer here:




  • Java Does Not Equal (!=) Not Working? [duplicate]

    7 answers



  • How do I compare strings in Java?

    23 answers



  • Android Studio .compareTo and .equals with strings not working

    6 answers








java android android-studio






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 13:43









PeterPeter

13




13




marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 13:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Mike M. android
Users with the  android badge can single-handedly close android questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 25 '18 at 13:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Change it to if (!palabra.equals(palabrafin)) ....

    – Mike M.
    Nov 25 '18 at 13:47











  • Ok i did it but now if i put a diferent word of palabrafin also do the intent

    – Peter
    Nov 25 '18 at 13:52











  • Move all of the String palabra* = ... lines, and the palabra = ... line to inside onClick(), before the compare() call.

    – Mike M.
    Nov 25 '18 at 13:55













  • Yes that was the solution! Thnaks Mike i didnt realize.

    – Peter
    Nov 25 '18 at 13:56











  • No problem. Sorry I didn't catch that to begin with. I'll update the duplicate list with an appropriate link. Glad you got it working. Cheers!

    – Mike M.
    Nov 25 '18 at 13:59





















  • Change it to if (!palabra.equals(palabrafin)) ....

    – Mike M.
    Nov 25 '18 at 13:47











  • Ok i did it but now if i put a diferent word of palabrafin also do the intent

    – Peter
    Nov 25 '18 at 13:52











  • Move all of the String palabra* = ... lines, and the palabra = ... line to inside onClick(), before the compare() call.

    – Mike M.
    Nov 25 '18 at 13:55













  • Yes that was the solution! Thnaks Mike i didnt realize.

    – Peter
    Nov 25 '18 at 13:56











  • No problem. Sorry I didn't catch that to begin with. I'll update the duplicate list with an appropriate link. Glad you got it working. Cheers!

    – Mike M.
    Nov 25 '18 at 13:59



















Change it to if (!palabra.equals(palabrafin)) ....

– Mike M.
Nov 25 '18 at 13:47





Change it to if (!palabra.equals(palabrafin)) ....

– Mike M.
Nov 25 '18 at 13:47













Ok i did it but now if i put a diferent word of palabrafin also do the intent

– Peter
Nov 25 '18 at 13:52





Ok i did it but now if i put a diferent word of palabrafin also do the intent

– Peter
Nov 25 '18 at 13:52













Move all of the String palabra* = ... lines, and the palabra = ... line to inside onClick(), before the compare() call.

– Mike M.
Nov 25 '18 at 13:55







Move all of the String palabra* = ... lines, and the palabra = ... line to inside onClick(), before the compare() call.

– Mike M.
Nov 25 '18 at 13:55















Yes that was the solution! Thnaks Mike i didnt realize.

– Peter
Nov 25 '18 at 13:56





Yes that was the solution! Thnaks Mike i didnt realize.

– Peter
Nov 25 '18 at 13:56













No problem. Sorry I didn't catch that to begin with. I'll update the duplicate list with an appropriate link. Glad you got it working. Cheers!

– Mike M.
Nov 25 '18 at 13:59







No problem. Sorry I didn't catch that to begin with. I'll update the duplicate list with an appropriate link. Glad you got it working. Cheers!

– Mike M.
Nov 25 '18 at 13:59














0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks