簡體   English   中英

登錄按鈕未正確設置Textview文本Android

[英]Login button not setting the textview text correctly Android

我現在已經忙了很長時間,而且我不知道為什么按下按鈕時文本設置不正確。 它在其他任何地方都正確設置,而不僅僅是這個位置。 我嘗試在不同的地方移動它,但仍然沒有效果。 第一個loginSuccess.setText(“ Checking Credintails”); 不管用。 其他人在讓我感到困惑的代碼中工作正常。 任何幫助,將不勝感激。loginSuccess.setText(“ Checking Credintails”); 按下按鈕時應調用。

這是我的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);
            }

        }
    });

謝謝大家的幫助。 我想出了什么與setText()問題有關。 我在某種程度上進行了更改,因此它會發生變化,但是UI在開始從服務器下載數據之前不會更新。 因此,下載是在接管線程,而不是讓UI更新和更改。 因此,這就是后來的setText起作用而第一個setText不能起作用的原因。 將所有下載內容放入其自己的線程后,設置的文本可以正常工作。 非常感謝大家的幫助,您的所有想法使我重新思考並解決了這個問題。 再次感謝你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM