mardi 20 janvier 2015

why is this part of my code not following the loop?

I am working on an app that takes in input from the user and adds it to a list view in android.


i decided I wanted to make a control to keep the user from adding empty strings to the list, as it would clutter the screen uselessly. I wrote this code for that.



public void addClaims(View v){
ClaimListController ct = new ClaimListController();
EditText textView = (EditText) findViewById(R.id.add_claim_field);
String added = textView.getText().toString();

if (added != ""){
final String t = format("added",added);
ct.addClaim(new Claim(added));
Toast.makeText(this, t, Toast.LENGTH_SHORT).show();
textView.setText("");
//Intent intent = new Intent(MainActivity.this, AddClaim.class);
//startActivity(intent);
}else{
Toast.makeText(AddClaim.this,"Please type something before adding", Toast.LENGTH_SHORT).show();
}
}
private String format(String string, String added) {
String formats = string +" "+ added;
return formats;
}


however, the if(){} loop is never checked. I tried changing the empty string to "test" and adding test in the app, and it still worked. what is causing the code to NOT check the IF and ELSE conditions?


Aucun commentaire:

Enregistrer un commentaire