How to put validation in Android app

320 views Asked by At

How can I put validation on logout button in an android app, If I am using SocialAuthAdapter in my app for sharing with social media. Code is as follows which I have write to validate my logout button but it dosent work:

public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.back:
        Route_stops.this.finish();
        break;
    case R.id.update:

        edit = (EditText) findViewById(R.id.editTxt);
        String msg=edit.getText().toString();

        Log.v("update1", "update1"+msg);
        if(msg.equals(""))
        {
            Toast.makeText(Route_stops.this, "You have to write something for updation", 100).show();
        }
        break;
    case R.id.logoutbutton:
        /*Intent logout  = new Intent(Route_stops.this,Logout.class);
        startActivity(logout);*/
        if(adapter==null)
        {

            Toast.makeText(Route_stops.this, "You have to sign in first", 100).show();
        }
        else{
            try{
                /*CookieSyncManager.createInstance(this); 
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.removeAllCookie();*/
            adapter.signOut(Route_stops.this,Provider.FACEBOOK.toString());
            adapter.signOut(Route_stops.this,Provider.TWITTER.toString());
            adapter.signOut(Route_stops.this,Provider.LINKEDIN.toString());
            adapter.signOut(Route_stops.this,Provider.MYSPACE.toString());
            if(Provider.FACEBOOK==null && Provider.TWITTER==null && Provider.LINKEDIN==null && Provider.MYSPACE==null)
                Toast.makeText(Route_stops.this, "You have Logged In First in any Social media", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(Route_stops.this, "You have Logged Out", Toast.LENGTH_LONG).show();
            }
            catch(Exception E)
            {
                System.out.println(E.toString());
            }
        }

        break;
    case R.id.option:
        Toast.makeText(Route_stops.this, "Map", 100).show();


    }
1

There are 1 answers

0
Piyush On BEST ANSWER

Change with this:

if(Provider.FACEBOOK.isEmpty() && Provider.TWITTER.isEmpty() && Provider.LINKEDIN.isEmpty() && Provider.MYSPACE.isEmpty())
            Toast.makeText(Route_stops.this, "You have Logged In First in any Social media", Toast.LENGTH_LONG).show();
        else
            Toast.makeText(Route_stops.this, "You have Logged Out",  Toast.LENGTH_LONG).show();
        }

OR

 if(Provider.FACEBOOK.equals("") && Provider.TWITTER.equals("") && Provider.LINKEDIN.equals("") && Provider.MYSPACE.equals(""))
            Toast.makeText(Route_stops.this, "You have Logged In First in any Social media", Toast.LENGTH_LONG).show();
        else
            Toast.makeText(Route_stops.this, "You have Logged Out",  Toast.LENGTH_LONG).show();
        }