---
title: "TextView 为空判别"
author: "AndLi"
date: "2012-02-27T22:24:49Z"
tags: []
categories: ["移动开发"]
slug: "textview"
draft: false
lastmod: "2012-02-27T22:24:49Z"
id: 1428037
url: "https://andli.iteye.com/blog/1428037"
---

```
String user = username_et.getText().toString().trim();
		String pd = password_et.getText().toString().trim();
		if (TextUtils.isEmpty(user)) {
			username_et.setError("用户名不能为空！");
			username_et.requestFocus();
			username_et.setText("");
			return;
			// ToastHelp.showToast(this, "用户名或密码不能为空！", 1000);
		}
```

 

![](http://dl.iteye.com/upload/attachment/0063/8534/f9291dec-9517-3a07-9032-c8b48f469339.jpg)