下面的代码片段显示了一个带有简单登录表单的Dialog.问题是当用户点击登录按钮时,输入到EditTexts的文本不会在getText() – 调用上返回.但是,如果我在xml-layout的EditTexts上设置
android:setText =“foo”,则在getText()上返回“foo”.知道为什么在运行时输入的文本不会粘住?
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>
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。