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