I am writing an app that takes two user inputs and matches them to data stored in a database and displays the corresponding data(row) from the user inputs in a TextView.
The if statement works perfectly alone if the condition is true. It is however not executed even if the condition is true if I add the else statement.
The else statement is always executed if the statement is true or false
protected void onPostExecute(Void v) { // ambil data dari Json database try { JSONArray Jarray = new JSONArray(result); for (int i = 0; i < Jarray.length(); i++) { JSONObject Jasonobject = null; //text_1 = (TextView)findViewById(R.id.txt1); Jasonobject = Jarray.getJSONObject(i); //get an output on the screen //String id = Jasonobject.getString("id"); String name = Jasonobject.getString("name"); String db_detail=""; if (et.getText().toString().equalsIgnoreCase(name)) { db_detail = Jasonobject.getString("detail"); text.setText(db_detail); break; } else { Toast.makeText(MainActivity.this, "Not available", Toast.LENGTH_LONG).show(); break; } } this.progressDialog.dismiss();