0

First of all,i've checked a couple of threads asking about this very same thing,and according to my understanding it seems i need to inflate a seperate view in the same method i'm going to use .getText() and also typecaste the same,but it doesn't seem to work,correct me if i'm wrong.

This is my OnClick where i'm trying to get the Edittext value

 @Override
public void onClick(View v) {
    LayoutInflater inflater1 = LayoutInflater.from(this);
    root1 = (ViewGroup) findViewById(R.id.main_root);
    View popupContentView1 = inflater1.inflate(R.layout.codepopup, root1, false);

    code = (EditText) popupContentView1.findViewById(R.id.codeEt);
    btnauthorize = (Button)popupContentView1.findViewById(R.id.btnAuth);
    btnauthorize.setOnClickListener(this);
    btnfree =(Button)popupContentView1.findViewById(R.id.btnFree);
    btnfree.setOnClickListener(this);

    String temp;
    Intent intent;
    switch (v.getId()) {

        case R.id.btnAccess:
            showPopup(popupContentView1, root, Gravity.CENTER, 0, 0);
            break;

        case R.id.btnAuth:
          final String cd = code.getText().toString();
            if(pwd != null) {
               if (code.getText().toString() == pwd) {
                   showToast("Authorization is Successful!");
                    signup.setVisibility(View.VISIBLE);
                   login.setEnabled(true);
                   if(active!=null)
                   {
                       active.dismiss();
                       active=null;
                   }
               }
               else{showToast("Please enter a valid Code!");signup.setVisibility(View.INVISIBLE); }
           }
            break;

Please let me know if i'm missing something,i'm getting "" in cd,any inputs would be helpfull

  • Hey Sam compare your string like this >>> cd.equals(pwd); – Harin Kaklotar Jul 11 '17 at 05:23
  • get what you are trying to imply,but thats not issue,i even used a toast to display (code.getText().toString()) and it still shows "" –  Jul 11 '17 at 05:44
  • I am saying is that you are compare string in wrong way. Some time it may generate error. So it's good to use .equals() – Harin Kaklotar Jul 11 '17 at 05:56
  • 1
    Where are you creating the popup window? It is "" because the editText has no text. – Ali Jul 11 '17 at 06:03
  • @Ali the popupwindow is getting created in btnAccess,i've used a method called as showPopup –  Jul 11 '17 at 06:12
  • @HarinKaklotar i know,but i need to figure this out first –  Jul 11 '17 at 06:13
  • Move editText, Buttons initializations and their onClickListeners below showPopup() method and then try it. – Ali Jul 11 '17 at 06:22

3 Answers3

0

change

code.getText().toString() == pwd

to

code.getText().toString().equals(pwd)
Rasoul Miri
  • 11,234
  • 1
  • 68
  • 78
  • I get what you are trying to imply,but thats not issue,i even used a toast to display (code.getText().toString()) and it still shows "" –  Jul 11 '17 at 05:43
0

@Override public void onClick(View v) { LayoutInflater inflater1 = LayoutInflater.from(this); root1 = (ViewGroup) findViewById(R.id.main_root); View popupContentView1 = inflater1.inflate(R.layout.codepopup, root1, false);

btnauthorize = (Button)popupContentView1.findViewById(R.id.btnAuth);
btnauthorize.setOnClickListener(this);
btnfree =(Button)popupContentView1.findViewById(R.id.btnFree);
btnfree.setOnClickListener(this);

String temp;
Intent intent;
switch (v.getId()) {

    case R.id.btnAccess:
        showPopup(popupContentView1, root, Gravity.CENTER, 0, 0);
        break;

    case R.id.btnAuth:
      final String cd = code.getText().toString();
        if(pwd != null) {
            code = (EditText) popupContentView1.findViewById(R.id.codeEt);
           if (code.getText().toString().equals(pwd)) {
               showToast("Authorization is Successful!");
                signup.setVisibility(View.VISIBLE);
               login.setEnabled(true);
               if(active!=null)
               {
                   active.dismiss();
                   active=null;
               }
           }
           else{showToast("Please enter a valid Code!");signup.setVisibility(View.INVISIBLE); }
       }
        break;
  • I get what you are trying to imply,but thats not the issue,i even used a toast to display (code.getText().toString()) and it still shows "" –  Jul 11 '17 at 05:44
0

Move the editText and Button(s) initializations and setonClickListeners below showPopup() method.

@Override public void onClick(View v) { 
    LayoutInflater inflater1 = LayoutInflater.from(this); 
    root1 = (ViewGroup) findViewById(R.id.main_root); 
    View popupContentView1 = inflater1.inflate(R.layout.codepopup, root1, false);  
    String temp; Intent intent; 
    switch (v.getId()) { 
         case R.id.btnAccess: 
              showPopup(popupContentView1, root, Gravity.CENTER, 0, 0); 
              code = (EditText) popupContentView1.findViewById(R.id.codeEt); 
              btnauthorize = (Button) popupContentView1.findViewById(R.id.btnAuth); 
              btnauthorize.setOnClickListener(this); 
              btnfree =(Button)popupContentView1.findViewById(R.id.btnFree); 
              btnfree.setOnClickListener(this); 
         break; 
         case R.id.btnAuth: 
              final String cd = code.getText().toString(); 
              if(pwd != null) { 
                   if (code.getText().toString() == pwd) { 
                        showToast("Authorization is Successful!"); 
                        signup.setVisibility(View.VISIBLE); 
                        login.setEnabled(true); 
                             if(active!=null) { 
                                  active.dismiss(); 
                                  active=null; 
                             } 
                   } else {
                   showToast("Please enter a valid Code!");
                   signup.setVisibility(View.INVISIBLE); } 
              } 
         break;
    }
}
Ali
  • 839
  • 11
  • 21