Nam Jayer Nam Jayer - 2 months ago 13
Android Question

Android: Get text Editext == item array

I have this code

if(edt_i.getText().toString() == Arrays.asList(coupon).contains("VIP537129")) {
Toast.makeText(MainActivity.this,"50% ",
Toast.LENGTH_SHORT).show();


My Array

String[] coupon = {
"MEM537128",
"MEM537129",
"VIP537128",
"VIP537129"
};


I want to check text in Edittext with Array, But didn't working. Please help me!

EDIT

if (Arrays.asList(coupon).contains(edt_i.getText().toString())) {
Toast.makeText(MainActivity.this,"10% ",
Toast.LENGTH_SHORT).show();
}else if(Arrays.asList(coupon).contains(edt_i.getText().toString())) {
Toast.makeText(MainActivity.this,"20% ",
Toast.LENGTH_SHORT).show();
}else if(Arrays.asList(coupon).contains(edt_i.getText().toString())) {
Toast.makeText(MainActivity.this," 30% ",
Toast.LENGTH_SHORT).show();
}else if(Arrays.asList(coupon).contains(edt_i.getText().toString())) {
Toast.makeText(MainActivity.this,"50% ",
Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(MainActivity.this," False ",
Toast.LENGTH_SHORT).show();
}


But Toast only show 10%

Answer

not sure about your question. is this what u need ?

int[] percent = {10,20,30,50};


 if(Arrays.asList(coupon).contains(edt_i.getText().toString())) 
{
Toast.makeText(MainActivity.this,percent[Arrays.asList(bigger).indexOf(edt_i.getText().toString())].toString()+"%", 
                                        Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(MainActivity.this," False ", 
                            Toast.LENGTH_SHORT).show();
}