你好,我是Android开发的初学者。我想在EditText中显示来自xampp(phpmyadmin)的数据,如果EditText值不等于“"(来自xampp的数据!="”),如果等于“"(来自xampp的数据=="”),我想让用户键入该值。{如果显示该值,它应该对用户不可编辑}我尝试了if.. else
`
if(DepartStation_txt!=""){
DS.setText(DepartStation_txt);
DS.setEnabled(false);
}else {
DS.setText("Enter the Value");
DS.setEnabled(true);
}
'其中DS是编辑文本DS=
(EditText) findViewById(R.id.DS);
在onCreate中
执行此工作的任何功能以及不工作的原因
1条答案
按热度按时间dxpyg8gm1#
只需使用
String
类的方法来比较字符串。现在,首先需要从EditText
控件读取文本,然后检查所需的字符串是否存在。对于您的情况,示例代码如下:请注意,我使用
setHint
方法而不是setText
方法,因为它更适合指导用户。