Search code examples
javaandroidtextviewsettext

Login button not setting the textview text correctly Android


I have been working at this for a hot minute now and I can't figure out why the text won't be set correctly when the button is pressed. It is set correctly everywhere else just not this spot. I tried moving it around in different places but still no effect. the first loginSuccess.setText("Checking Credintails"); is not working. The others work fine in the code which has me baffled. Any help with this would be appreciated.The loginSuccess.setText("Checking Credintails"); should be called when the button is pushed.

So here is my code for the button OnClick

login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            loginSuccess.setText("Checking Credintails");

            //test to see if there is a connection
            ConnectionTester ct = new ConnectionTester();
            boolean online = ct.isOnline(v.getContext());
            boolean issue = false;


            Tracker longinTracker = ((AnalyticsApplication) getApplication()).getDefaultTracker();
            userName = user.getText().toString();
            passWord = pass.getText().toString();
            LoginJsonParser ljp = new LoginJsonParser();

            if(online)
            {
                try {
                    ljp.checkUsername(loginUrl, userName, passWord);
                    canLogin = ljp.returnedResult;

                } catch (IOException e) {
                    e.printStackTrace();
                }catch (NullPointerException ne)
                {
                    issue = true;
                    loginSuccess.setText("接続の問題");
                    Log.d("Null point ", "Jsonl login");
                }
                //if(userName.equals("admin") && passWord.equals("admin")0
                if(canLogin == true)
                {
                    //Write to the ShardedPreference to store for later use
                    Log.d("My user name " , userName);
                    Log.d("My Password " , passWord);
                    MySharedPerference.writeString(getApplicationContext(),MySharedPerference.USERNAME, userName);
                    MySharedPerference.writeString(getApplicationContext(),MySharedPerference.PASSWORD, passWord);
                    //build login event
                    //call this first otherwise it may not be called and wont post to the servers
                    longinTracker.send(new HitBuilders.EventBuilder()
                                    .setCategory(getString(R.string.eventCategory))
                                    .setAction(getString(R.string.loginevent))
                                    .build()
                    );
                    //Start downloaing and processing customer data
                    //Also open up the Loading screeen animation
                    loadingImage.setVisibility(View.VISIBLE);
                    loginSuccess.setText("Loging you in now");
                    donwloadCustomerData();

                }else
                {
                    if(issue != true)
                    {
                        loginSuccess.setText("パスワードが違います");
                    }else{
                        loginSuccess.setText("接続に関する問題");
                    }

                }
            }else
            {
                Intent noCon = new Intent(v.getContext(), NoConnection.class);
                startActivity(noCon);
            }

        }
    });

Solution

  • Thank you everyone for helping with this. I figured what was happing with the setText() problem. I was changing right to a degree so it would change but the UI would not update before it started to download the data from the server. So the downloading was taking over the thread and not letting the UI update and change. so that is why the later setText worked but not the first setText. After I put all the downloading into its own thread the set text works fine. I appreciate everyones help with this all your ideas lead me to think about this in a new light and solve this issue. Thank you again.