如果讓你判斷一個文本框是否為空(null)或者沒有任何值(length=0),你會怎么怎樣去寫代碼,很多初學者可能會這樣寫:
if(text==null || text.length==0)
{........}
其實沒有必要這么麻煩,在android的官方API中有更方便的解決方法:Returns true if the string is null or 0-length,可以使用這個方法-TextUtils.isEmpty()
可以這樣寫:
if(!TextUtils.isEmpty(text))
{.....}