private voID showLogindisplay() { loginDialog = new Dialog(GOfdroID.this); loginDialog.getwindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND); loginDialog.setTitle("Logga in"); LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); VIEw dialogVIEw = li.inflate(R.layout.login_dialog,null); loginDialog.setContentVIEw(dialogVIEw); loginDialog.show(); button loginbutton = (button) dialogVIEw.findVIEwByID(R.ID.login_button); button cancelbutton = (button) dialogVIEw.findVIEwByID(R.ID.cancel_button); EditText unameVIEw = (EditText) dialogVIEw.findVIEwByID(R.ID.uname_ID); if (unameVIEw != null) Log.d(TAG,"unameVIEw != null"); Log.d(TAG,"uname.getText(): " + unameVIEw.getText().toString()); uname = unameVIEw.getText().toString(); EditText pwdVIEw = (EditText) dialogVIEw.findVIEwByID(R.ID.pwd_ID); if (pwdVIEw != null) pwd = pwdVIEw.getText().toString(); Log.d(TAG,"uname = " + uname + ",pwd = " + pwd); loginbutton.setonClickListener(new OnClickListener() { //@OverrIDe public voID onClick(VIEw v) { Log.d(TAG,"Clicked <logga in>"); loginDialog.dismiss(); vIEwEvents = new Runnable() { //@OverrIDe public voID run() { getEvents(uname,pwd); } }; Thread thread = new Thread(null,vIEwEvents,"MagentoBackground"); thread.start(); pDialog = ProgressDialog.show(GOfdroID.this,"Uppdaterar...","Hämtar registrerade körningar...",true); } });}
和XML:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:paddingleft="10dip" androID:paddingRight="10dip"><TextVIEw androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:text="@string/uname_label"/><EditText androID:ID="@+ID/uname_ID" androID:layout_wIDth="220dip" androID:layout_height="wrap_content" androID:text="foo" /><TextVIEw androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:text="@string/pwd_label" androID:paddingtop="10dip"/><EditText androID:ID="@+ID/pwd_ID" androID:layout_wIDth="220dip" androID:layout_height="wrap_content" androID:text="" androID:inputType="textPassword" /><linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:paddingtop="15dip"><button androID:ID="@+ID/login_button" androID:layout_wIDth="100dip" androID:layout_height="fill_parent" androID:text="Logga in" /><button androID:ID="@+ID/cancel_button" androID:layout_wIDth="100dip" androID:layout_height="fill_parent" androID:text="Avbryt" /></linearLayout></linearLayout>解决方法 问题是你没有在匿名内部类中更新uname和pwd.只有在调用showLogindisplay()方法时才更新uname和pwd.当用户更改文本并点击登录按钮时,将调用onClick()方法.
在你想要做的内部类的onClick()方法中:
uname = unameVIEw.getText();pwd = pwdVIEw.getText();
您必须创建unameVIEw和pwdVIEw全局/字段变量,因此匿名内部类可以访问它们.
你必须这样做的原因是因为当按下登录按钮时,只运行具有匿名内部类的onClick的代码.
我希望能解决这个问题.
总结以上是内存溢出为你收集整理的android – EditText不返回getText()上的内容全部内容,希望文章能够帮你解决android – EditText不返回getText()上的内容所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)