application showing wrong Toast message
<p>My application is not showing a <code>Toast</code> message when the user failed to fill in the <code>EditText</code>.</p>

<p>When pressing the login <code>Button</code> the user should see a <code>Toast</code> reminding them to fill in the input box, but it is only displaying a <code>Toast</code> telling the user to check their internet connection.</p>

<p><strong>Why is the right <code>Toast</code> not showing?</strong></p>

<pre><code>package com.mypackage;

import java.util.List;

import com.mypackage.login.parser.LoginData;
import com.mypackage.login.parser.LoginXmlPullFeedParser;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
 import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
 import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
 import android.widget.TextView;
import android.widget.Toast;

  public class LoginScreen extends Activity {

Animation myAnimation;
ImageView myImageView;

EditText mobile;
EditText pin;
Button btnLogin;
Button btnClear;
Spinner sp;

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

ProgressDialog myProgressDialog = null;

String feedUrl;

List&lt;LoginData&gt; userData;

Handler handle = new Handler(){


    public void handleMessage(android.os.Message msg) {

         if (msg.what == 1)
        {

            hideProgress();
                Toast.makeText(getApplicationContext(), "Please 
    enter correct memberID and password ", Toast.LENGTH_LONG).show();


            if(userData != null)
            {



            }



            else
            {
                Toast.makeText(getApplicationContext(), "Please 
   enter correct memberID and password ", Toast.LENGTH_LONG).show();
            }

        }
        else if (msg.what == 2)
        {
            hideProgress();



            Toast.makeText(getApplicationContext(), "Please check 
  internet", Toast.LENGTH_LONG).show();
        }
        super.handleMessage(msg);
    };
};

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.agapplogin);



    myAnimation = AnimationUtils.loadAnimation(this, R.anim.myanim);
    myImageView = (ImageView) this.findViewById(R.id.myImageView);
    myImageView.startAnimation(myAnimation);


    TextView lblMobileNo = (TextView) findViewById(R.id.lblMobileNo);


  lblMobileNo.setTextColor(getResources().getColor(R.color.text_color_black));

    mobile = (EditText) findViewById(R.id.txtMobileNo);



    TextView lblPinNo = (TextView) findViewById(R.id.lblPinNo);
    lblPinNo.setTextColor(getResources().getColor(R.color.text_color_black));

    pin = (EditText) findViewById(R.id.txtPinNo);



    btnLogin = (Button) findViewById(R.id.btnLogin);
    btnLogin.setTextColor(getResources().getColor(R.color.text_color_blue));
    btnClear = (Button) findViewById(R.id.btnClear);
    btnClear.setTextColor(getResources().getColor(R.color.text_color_blue));

/*  btnLogin.setOnClickListener(new OnClickListener() {

        public  void onClick(View view) {


            checkinvalidinput();



            showProgress();
             new Thread() {

                    public void run() {
                         try
                        {

                            postLoginData();
                            android.os.Message alertMessage = new 
     android.os.Message();
                            alertMessage.what = 1;
                            handle.sendMessage(alertMessage);
                        }
                        catch(Exception e)
                        {

                            android.os.Message alertMessage = new 
         android.os.Message();
                            alertMessage.what = 2;
                            handle.sendMessage(alertMessage);
                        }
                    }
                }.start();

        }
    });
       */
    btnClear.setOnClickListener(new OnClickListener() {
        public void onClick(View v)

        {
            cleartext();
        }

    });

     Spinner sp = (Spinner) findViewById(R.id.lgnspinner);

    ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
            this, R.array.network_array,
            android.R.layout.simple_spinner_item);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    sp.setAdapter(adapter);

    sp.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                int position, long id) {

            if (position == 0)

            {

            TelephonyManager tempManager;
                tempManager = (TelephonyManager) 
  getSystemService(Context.TELEPHONY_SERVICE);
                int networkType = tempManager.getNetworkType();

                if (networkType == 
      TelephonyManager.NETWORK_TYPE_GPRS) {
                    btnLogin.setOnClickListener(new 
    OnClickListener() {

                        public  void onClick(View view) {


                            checkinvalidinput();



                            showProgress();
                             new Thread() {

                                    public void run() {
                                         try
                                        {


      postLoginData();

                                android.os.Message alertMessage = 
        new android.os.Message();



        alertMessage.what = 1;

                            handle.sendMessage(alertMessage);
                                        }
                                        catch(Exception e)
                                        {


          android.os.Message alertMessage = new android.os.Message();

        alertMessage.what = 2; 

          handle.sendMessage(alertMessage);
                                        }
                                    }
                                }.start();

                        }
                    });






                } else if (networkType != 
        TelephonyManager.NETWORK_TYPE_GPRS) {
                    Toast.makeText(LoginScreen.this,
                            "No GPRS Connection Found 
           ", Toast.LENGTH_LONG)
                            .show();
                }

            }


            if (position == 1) {

                final ConnectivityManager connMgr = 
      (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

                final android.net.NetworkInfo wifi = connMgr

        .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                if (wifi.isAvailable()) {
                    Toast.makeText(LoginScreen.this, " Wifi 
   Found",
                            Toast.LENGTH_LONG).show();
                    btnLogin.setOnClickListener(new 
  OnClickListener() {

                        public  void onClick(View view) {






                            showProgress();
                             new Thread() {

                                    public void run() {
                                         try
                                        {


    postLoginData();

     android.os.Message alertMessage = new android.os.Message();

       alertMessage.what = 1;

     handle.sendMessage(alertMessage);
                                        }
                                        catch(Exception e)
                                        {


            android.os.Message alertMessage = new android.os.Message();

     alertMessage.what = 2;

      handle.sendMessage(alertMessage);
                                        }
                                    }
                                }.start();

                        }
                    });
                } else if (!wifi.isAvailable()) {
                    Toast.makeText(LoginScreen.this, "No Wifi  
      found ",
                            Toast.LENGTH_LONG).show();
                }

            }

            if (position == 2)

            {

        if (mBluetoothAdapter == null) {
                    Toast.makeText(LoginScreen.this,
                            "No BlueTooth Support ",  
             Toast.LENGTH_LONG)
                            .show();
                } else {
                    if (mBluetoothAdapter.isEnabled()) {
                        if 
   (mBluetoothAdapter.isDiscovering()) {
                            Toast.makeText(

   LoginScreen.this,

     "Bluetooth  is currently in device discovery process.",

   Toast.LENGTH_LONG).show();

                        } else {

  Toast.makeText(LoginScreen.this,
                                    "Bluetooth 
     is Enabled.",

   Toast.LENGTH_LONG).show();

     btnLogin.setOnClickListener(new OnClickListener() {

                                public  void 
      onClick(View view) {








      showProgress();
                                     new 
      Thread() {

                                            public 
     void run() {
                                                        try
                                                {

                                                    postLoginData();
                                                    android.os.Message alertMessage = new android.os.Message();
                                                    alertMessage.what = 1;
                                                    handle.sendMessage(alertMessage);
                                                }

    catch(Exception e)
                                                {

                                                    android.os.Message alertMessage = new android.os.Message();
                                                    alertMessage.what = 2;
                                                    handle.sendMessage(alertMessage);
                                                }
                                            }
                                        }.start();

                                }
                            });
                        }
                    } else {
                        Toast.makeText(LoginScreen.this,
                                "Bluetooth is NOT  
  Enabled!",

   Toast.LENGTH_LONG).show();

                    }
                }

            }

            if (position == 3)

            {

                final ConnectivityManager connMgr =  
         (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo activeNetworkInfo = connMgr
                        .getActiveNetworkInfo();
                android.net.NetworkInfo mobile1 = connMgr

      .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

                if (activeNetworkInfo == null) {
                    Toast.makeText(LoginScreen.this, "No 
       Active Network",
                            Toast.LENGTH_LONG).show();
                } else {

                    if (activeNetworkInfo.isConnected()) {
                        Toast.makeText(LoginScreen.this,
                                "network is 
      Connected", Toast.LENGTH_LONG)
                                .show();
                        btnLogin.setOnClickListener(new 

   OnClickListener() {

                            public  void onClick(View 
  view) {






                                showProgress();
                                 new Thread() {

                                        public void 
        run() {
                                             try
                                            {


           postLoginData();

         android.os.Message alertMessage = new android.os.Message();

        alertMessage.what = 1;

        handle.sendMessage(alertMessage);
                                            }

        catch(Exception e)
                                            {


       android.os.Message alertMessage = new android.os.Message();

       alertMessage.what = 2;

          handle.sendMessage(alertMessage);
                                            }
                                        }
                                    }.start();

                            }
                        });

                    } else if  
       (activeNetworkInfo.isConnectedOrConnecting()) {
                        Toast.makeText(LoginScreen.this,
                                "network is 
    Connecting", Toast.LENGTH_LONG)
                                .show();
                    } else if (mobile1.isAvailable()) {

                        btnLogin.setOnClickListener(new 
      OnClickListener() {

                            public  void onClick(View 
     view) {






                                showProgress();
                                 new Thread() {

                                        public void 
      run() {
                                             try
                                            {


        postLoginData();

     android.os.Message alertMessage = new android.os.Message();

      alertMessage.what = 1;

     handle.sendMessage(alertMessage);
                                            }

   catch(Exception e)
                                            {


 android.os.Message alertMessage = new android.os.Message();

       alertMessage.what = 2;

      handle.sendMessage(alertMessage);
                                            }
                                        }
                                    }.start();

                            }
                        });
                    } else if (!mobile1.isAvailable()) {
                        Toast.makeText(LoginScreen.this,
                                "No other 
             Connection Found ",

       Toast.LENGTH_LONG).show();
                    }
                }

            }


        }

        public void onNothingSelected(AdapterView&lt;?&gt; arg0) {

        }

    });
}



public void postLoginData()

{

if (pin.getTextSize() == 0 || mobile.getTextSize() == 0) {

        AlertDialog.Builder altDialog = new AlertDialog.Builder(this);
    altDialog.setMessage("Please Enter Complete Information!");

    } else {
        LoginParser();
        Intent i = new Intent(this.getApplicationContext(), 
      AgAppMenu.class);
        Bundle bundle = new Bundle();
        bundle.putString("mno", mobile.getText().toString());
        bundle.putString("pinno", pin.getText().toString());
        i.putExtras(bundle);
        startActivity(i);

    }
    cleartext();
     }

public void onClick(View v) {


}

public void cleartext() {

    {
        pin.setText("");
        mobile.setText("");
    }

}

 private void showProgress()
    {




        myProgressDialog = ProgressDialog.show(LoginScreen.this,null, 
                "Loading...", true);

    }

private void hideProgress()
    {
        if (myProgressDialog != null)
            myProgressDialog.dismiss();
    }

 private void LoginParser(){


     String mno=mobile.getText().toString();
        String pinno=pin.getText().toString();


        feedUrl = "https://demo.accessgroup.mobi/AG_IT_App 
  /AgMainServlet?messageType=LOG&amp;pin="  + pinno + "&amp;mobile=" + mno + "&amp;source=" + 
   mno  + "&amp;channel=INTERNET";

        Log.e("Login",feedUrl+" ");
        LoginXmlPullFeedParser parser = new 
    LoginXmlPullFeedParser(feedUrl);
        //checkinvalidinput();
        userData = parser.parse();

 }
            }
</code></pre>
