歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發教程:代替System.out.println的方法

Android開發教程:代替System.out.println的方法

日期:2017/3/1 10:52:40   编辑:Linux編程

剛開始學用Andriod開發,覺得System.out.println 不太好用,網上查到了替代的方法,即調用Android自帶的類在Logcat中輸出信息,代碼如下

  1. import android.util.Log;
  2. public class Util {
  3. private final static String TAG = "PrintOut";
  4. public static void PrintTextLog(String log) {
  5. Log.v(TAG, log);
  6. }
  7. }
其中TAG就是輸出信息時的標簽,調用方法為 Log.v (String tag, String message)。
Debug時候開啟Logcat窗口(Window -> Show View -> LogCat),添加一個過濾器(filter),“by log tag"設為自定義的TAG即可。
Copyright © Linux教程網 All Rights Reserved