嘿所以基本上我有一個應用程序的登錄/註冊屏幕,我必須使用ExpandableListView如圖所示。無法獲得在ExpandableListView中輸入編輯文本的字符串(不是通常的焦點問題)
根據孩子在一個小組中的位置我誇大了不同的意見。所以對於位置0和1,我已經誇大了2個不同的EditText框。
我的問題是我無法獲得在這兩個框中鍵入的文本。
該框允許我連續鍵入,但是當我單擊登錄按鈕時,使用getText從用戶名和密碼框中獲得的字符串都是空的!
Sign-In screen shot http://img801.imageshack.us/img801/5544/shot000005w.png Username Toast is blank http://img21.imageshack.us/img21/3825/shot000006y.png Password Toast is blank 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
}
這裏的Toast總是隻顯示你:和p:
有人幫忙!
我所有的建議首先是嘗試使用的getText()方法EDITTEXT和獲取數據第二,我想問你,你是如何解決在擴展列表視圖中編輯文本內部輸入文本的問題的。我仍然堅持這個問題,如果可能的話,你可以發佈你的代碼,所以我可以從中學習,因爲我還需要創建一個帶有editText和spinners的動態表單,該表單根據要輸入的記錄數重複。請幫助我如果你是因爲我的工作取決於它。我不是創造一個新的話題,因爲太多的限制和它或多或少可能是 – user1435153 2012-07-30 04:55:23
@ user1435153 嘿,謝謝,但我使用了TextWatcher。看看這篇文章,看看如何使用ExpandableListView(或ListView)中的EditText框來解決問題。(http://codersmusings.wordpress.com/2012/08/01/edittext-in-expandablelistview/) – Karan 2012-08-01 02:44:41