嗨大家为什么这段代码不工作? 我有TextView从sqlite数据库中获取值我想检查它是否隐藏TextView。TextView设置可见性,如果它空了
mTel1 = (TextView) findViewById(R.id.tv_tel1);
String ed_text = mTel1.getText().toString().trim();
if(ed_text.length() == 0 || ed_text.equals("") || ed_text == null)
{
mTel1.setVisibility(View.VISIBLE);
}
else
{
mTel1.setVisibility(View.GONE);
}
XML
<TextView
android:id="@+id/tv_tel1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:background="@drawable/border"
android:clickable="true"
android:padding="10dp"
android:textColor="#0066cc"
android:textSize="18sp" />
试试这个方式,如果(mTel1.getText()的toString()修剪。 ().length()> 0) –
您的条件需要更改,如果(ed_text.length()== 0 || ed_text.equals(“”)|| ed_text == null) { mTel1.setVisibility (View.GONE); } else { mTel1.setVisibility(View.VISIBLE); } – Sripathi