不能得到的字符串,可以订立ExpandableListView编辑文本(而不是通常的焦点问题) [英] Can't get String which is entered into Edit Text in ExpandableListView(Not the usual Focus issue)

查看:213
本文介绍了不能得到的字符串,可以订立ExpandableListView编辑文本(而不是通常的焦点问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿所以基本上我有一个登录/注册屏幕的应用程序,我有使用ExpandableListView使其如图所示。

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

根据孩子的我已经膨胀不同意见的一组中的位置。因此,对于位置0和1,我已膨胀2不同的EditText框。

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.

这个盒子可以让我不断地类型,但是当我点击登录按钮,字符串我使用的getText用户名和密码盒送都是空!

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!



下面是从CustomExpandableAdapter一开始getChildView:

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 )          
         username.setHint(c.getElement());

    }
   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 )          
         password.setHint(c.getElement());

   }
   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 )            
         et.setHint(c.getElement());
   }

   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);
       forgot.setOnClickListener(this);


   }


   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);
       sign_in.setOnClickListener(this); 

}
   return v;
}

和后来在code我有注册的onclick的按钮:

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


    }

下面的祝酒词总是只显示U:和p:

Here the Toasts always show just u: and p:

有人帮助!

推荐答案

我只是用一个TextWatcher(没有在此之前正常工作)
在code是在这里:

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

@Override
public void afterTextChanged(Editable s) {

    user_name=s.toString();
}
@Override
public void beforeTextChanged(CharSequence s, int start,
        int count, int after) {
    // TODO Auto-generated method stub

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


}

这篇关于不能得到的字符串,可以订立ExpandableListView编辑文本(而不是通常的焦点问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆