android gettext方法,android – EditText不返回getText()上的内容

下面的代码片段显示了一个带有简单登录表单的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 ");

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:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:paddingLeft="10dip"

android:paddingRight="10dip"

>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/uname_label"/>

android:id="@+id/uname_id"

android:layout_width="220dip"

android:layout_height="wrap_content"

android:text="foo" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/pwd_label"

android:paddingTop="10dip"/>

android:id="@+id/pwd_id"

android:layout_width="220dip"

android:layout_height="wrap_content"

android:text=""

android:inputType="textPassword" />

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:paddingTop="15dip"

>

android:id="@+id/login_button"

android:layout_width="100dip"

android:layout_height="fill_parent"

android:text="Logga in" />

android:id="@+id/cancel_button"

android:layout_width="100dip"

android:layout_height="fill_parent"

android:text="Avbryt" />

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值