Andr开发:检查EditText的内容是否为空白。如果空白,则在TextView里面显示:“请输入你的姓名!” 点击“确定”按钮后将EditText中的内容显示在TextView中。
时间: 2024-05-07 13:19:16 浏览: 14
好的,对于您的问题,可以使用以下代码实现:
```
Button button = findViewById(R.id.button);
final EditText editText = findViewById(R.id.editText);
final TextView textView = findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String inputText = editText.getText().toString().trim();
if (TextUtils.isEmpty(inputText)) {
textView.setText("请输入你的姓名!");
} else {
textView.setText(inputText);
}
}
});
```
其中,button为确定按钮,editText为输入框,textView为显示框。
在点击确定按钮后,会先获取输入框EditText中的内容,并使用trim()方法去掉首尾空白符。然后判断是否为空,如果为空,则在TextView中显示相应提示;否则,直接将内容显示在TextView中。
相关问题
德国艺术家André Heller创作的,名为“This is not America”的无声影像作品,请将作品在百度上搜索链接发给我
百度链接:https://www.baidu.com/s?wd=André+Heller+%E2%80%93+This+is+not+America&tn=baiduhome_pg&ie=utf-8&rsv_idx=2&rsv_dl=iy_2021
请介绍 scala v.andR v.orR v.xorR
`v.andR`、`v.orR` 和 `v.xorR` 是 Scala 中用于逻辑运算的方法。它们主要用于对集合或布尔型数据进行逻辑运算,并返回一个布尔值作为结果。
1. `v.andR`:这个方法接受一个集合作为参数,并返回该集合中所有元素的逻辑与(AND)运算结果。如果集合中所有元素都为真(true),则返回 true;否则返回 false。
示例:
```scala
val list = List(true, true, true)
val result = list.andR
println(result) // 输出 true
val list2 = List(true, false, true)
val result2 = list2.andR
println(result2) // 输出 false
```
2. `v.orR`:这个方法接受一个集合作为参数,并返回该集合中所有元素的逻辑或(OR)运算结果。如果集合中任何一个元素为真(true),则返回 true;否则返回 false。
示例:
```scala
val list = List(false, false, true)
val result = list.orR
println(result) // 输出 true
val list2 = List(false, false, false)
val result2 = list2.orR
println(result2) // 输出 false
```
3. `v.xorR`:这个方法接受一个集合作为参数,并返回该集合中所有元素的逻辑异或(XOR)运算结果。如果集合中存在奇数个 true 元素,则返回 true;如果集合中存在偶数个 true 元素,则返回 false。
示例:
```scala
val list = List(true, false, true)
val result = list.xorR
println(result) // 输出 false
val list2 = List(true, false, true, true)
val result2 = list2.xorR
println(result2) // 输出 true
```
这些方法可以帮助你对集合进行逻辑运算,并得到相应的结果。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)