如何在弹出窗口中显示Edittext的值

时间:2017-07-11 05:19:06

标签: android android-popupwindow

首先,我已经检查了几个线程,询问同样的事情,根据我的理解,似乎我需要用我将要使用的相同方法来夸大单独的视图.getText()和typecaste相同,但它似乎没有用,如果我错了,请纠正我。

这是我的OnClick,我试图获取Edittext值

 @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;

如果我错过了什么,请告诉我,我得到了""在cd中,任何输入都是有帮助的

3 个答案:

答案 0 :(得分:0)

更改

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

code.getText().toString().equals(pwd)

答案 1 :(得分:0)

@覆盖 public void onClick(查看v){     LayoutInflater inflater1 = LayoutInflater.from(this);     root1 =(ViewGroup)findViewById(R.id.main_root);     查看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;

答案 2 :(得分:0)

在showPopup()方法下面移动editText和Button(s)初始化和setonClickListeners。

@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;
    }
}