Android Log.d 由于 textView.getText().toString() 而未显示



前两个日志显示正常,但最后一个没有显示。即使最后一个日志的第二个参数有问题,我仍然很困惑为什么日志不只显示错误或其他内容。任何帮助,不胜感激。

@Override
public void onStart() {
    super.onStart();
    TextView country = (TextView) findViewById(R.id.country);
    Log.d("t1", "t1");
    Log.d("t2", country.toString());
    Log.d("t3", country.getText().toString());
}

以下是日志输出:

02-07 05:10:16.877 23305-23305/---bundle id--- D/t1: t1
02-07 05:10:16.877 23305-23305/---bundle id--- D/t2: android.support.v7.widget.AppCompatTextView{381dd943 V.ED..C. ......I. 0,0-0,0 #7f0e0089 app:id/country}

据我所知,如果TextView对象的getText()方法返回空字符串,记录器将不会为其输出条目。您可以尝试连接一些文本来描述输出中的预期内容。例如:

Log.d("t3", "Country TextView Value: " + country.getText().toString());

这种情况只有在 TextView 返回空字符串值时才可能。您需要添加一些带有Log的内容,如下所示:

Log.d("t3", "Country : " + country.getText().toString());

相关内容

最新更新