Android的Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
2010-05-14 16:56:00 来源:WEB开发网/ >
< Button
android:id="@+id/bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Presse Me Look Log"
/ >
< /LinearLayout >
Step 4:设计主类LogDemo.java,代码如下:
package com.android.test;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class LogDemo extends Activity {
private static final String ACTIVITY_TAG="LogDemo";
private Button bt;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//通过findViewById找到Button资源
bt = (Button)findViewById(R.id.bt);
//增加事件响应
bt.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
Log.v(LogDemo.ACTIVITY_TAG, "This is Verbose.");
Log.d(LogDemo.ACTIVITY_TAG, "This is Debug.");
Log.i(LogDemo.ACTIVITY_TAG, "This is Information");
Log.w(LogDemo.ACTIVITY_TAG, "This is Warnning.");
Log.e(LogDemo.ACTIVITY_TAG, "This is Error.");
}
});
}
}
Step 5:运行LogDemo工程,效果如下:
当我们点击按钮时,会触发事件,在Logcat视窗下有如下效果:
更多精彩
赞助商链接