- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- <Button
- android:id="@+id/bt"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Presse Me Look Log"
- />
- </LinearLayout>
- 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.");
- }
- });
- }
- }
本文出自 “ Android_Tutor ” 博客,请务必保留此出处 http://weizhulin.blog.51cto.com/1556324/311692