Karan Karan - 10 days ago 4x
Android Question

Can't get String which is entered into Edit Text in ExpandableListView(Not the usual Focus issue)

Hey so basically I have a Sign-in/Register screen for an app and I have to make it using an ExpandableListView as shown.

Based on the position of the child in a group I have inflated different views. So for positions 0 and 1, I have inflated 2 different EditText boxes.

My problem is I can't get the text that is typed in both the boxes.

The box allows me to type continuously but when I click the Sign-In button, the strings I get from the username and password boxes using getText are both null!

screen shot
Username Toast is blank
Password Toast is blank

Here's the get getChildView from the CustomExpandableAdapter:

public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
v = null;

position = 0;
position=getChildId(groupPosition, childPosition);

if(position==0) //draw the username editbox
v = inflater.inflate(R.layout.username, parent, false);
Element c = (Element)getChild( groupPosition, childPosition );
username = (EditText)v.findViewById( R.id.username);

if( username != null )

else if(position==1)
if(convertView == inflater.inflate(R.layout.password, parent, false))
return convertView;
v = inflater.inflate(R.layout.password, parent, false);
convertView = inflater.inflate(R.layout.password, parent, false);
Element c = (Element)getChild( groupPosition, childPosition );
password = (EditText)v.findViewById( R.id.password);
if( password != null )

else if (position>1023 && position<1028)
v = inflater.inflate(R.layout.child_row, parent, false);
Element c = (Element)getChild( groupPosition, childPosition );
et = (EditText)v.findViewById( R.id.et);

if( et != null )

else if(position==1028)

v = inflater.inflate(R.layout.gender, parent, false);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
context, R.array.gender, android.R.layout.simple_spinner_item );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
s = (Spinner) v.findViewById( R.id.spinner_gend );
s.setAdapter( adapter );

else if(position==2) //Forgot Button
v = inflater.inflate(R.layout.forgot, parent, false);
Button forgot = (Button)v.findViewById(R.id.fpb);


else if(position==3) //Sign-in Button
v = inflater.inflate(R.layout.sign_in_button, parent, false);
ImageButton sign_in = (ImageButton)v.findViewById(R.id.sign_in_button);

return v;

and later on in the code I have the onClick of the Sign in button:

case R.id.sign_in_button: {
String user_name = username.getText().toString();
String pass_word=password.getText().toString();
Toast.makeText(context,"u:"+ user_name, 3000).show();
Toast.makeText(context, "p:"+pass_word, 3000).show();
//Other unrelated Database Code


Here the Toasts always show just u: and p:

Someone help!


I just used a TextWatcher(which didn't work properly before this) The code is here:

public void afterTextChanged(Editable s) {

public void beforeTextChanged(CharSequence s, int start,
        int count, int after) {
    // TODO Auto-generated method stub

public void onTextChanged(CharSequence s, int start, int before,
        int count) {
    // TODO Auto-generated method stub