嘿,所以基本上我有一个应用程序的登录/注册屏幕,我必须使用 ExpandableListView 来制作它,如图所示。
根据孩子在小组中的位置,我夸大了不同的观点。所以对于位置 0 和 1,我已经膨胀了 2 个不同的 EditText 框。
我的问题是我无法获得在两个框中输入的文本。
该框允许我连续输入,但是当我单击登录按钮时,我使用 getText 从用户名和密码框中获得的字符串都是空的!
登录屏幕截图 http://img801.imageshack.us/img801/5544/shot000005w.png 用户名 Toast 为空 http://img21.imageshack.us/img21/3825/shot000006y.png 密码 Toast 为空 http:// /img542.imageshack.us/img542/8804/shot000007.png
这是来自 CustomExpandableAdapter 的 getChildView:
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;
}
稍后在代码中我有登录按钮的 onClick :
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
}
这里 Toasts 总是只显示 u: 和 p:
有人帮忙!