Android跟你打招呼
来源:互联网 发布:织梦tag标签静态化 编辑:程序博客网 时间:2024/04/29 20:00
package com.example.sayhello;import android.R.string;import android.os.Bundle;import android.app.Activity;import android.util.Log;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;//(内部处理类处理)public class MainActivity extends Activity {public final static String TAG = "MainActivity";private Button btnClick;private EditText tv_name; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取事件源 btnClick = (Button) findViewById(R.id.btnClick); tv_name = (EditText) findViewById(R.id.tv_name); btnClick.setOnClickListener(new btnClick()); } //事件处理类 class btnClick implements OnClickListener{@Overridepublic void onClick(View v) {String name = tv_name.getText().toString();Log.d(TAG,"name="+name);Toast.makeText(MainActivity.this ,"你好"+name, Toast.LENGTH_LONG).show();} } }//匿名内部类/*public class MainActivity extends Activity {public final static String TAG = "MainActivity";private Button btnClick;private EditText tv_name; @Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取事件源 btnClick = (Button) findViewById(R.id.btnClick); tv_name = (EditText) findViewById(R.id.tv_name); btnClick.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubString name = tv_name.getText().toString();Log.d(TAG,"name="+name);Toast.makeText(MainActivity.this ,"你好"+name, Toast.LENGTH_LONG).show();}}); }}*/
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@drawable/bg" tools:context=".MainActivity" > <EditText android:id="@+id/tv_name"android:hint="@string/sayHello" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="91dp" android:ems="10" > <requestFocus /> </EditText> <Button android:id="@+id/btnClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/click" /></RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">sayHello</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string name="sayHello">请输入你的名字</string> <string name="click">请点击我</string></resources>
0 0
- Android跟你打招呼
- Android------打招呼
- Android案例1 打招呼
- Android——打招呼
- Android中打招呼
- Android案例二,打招呼
- Android实现“打招呼”
- 初实android -打招呼
- 我来跟大伙打招呼了
- 打招呼
- 打招呼
- 打招呼
- 打招呼
- 打招呼
- 打招呼
- 打招呼
- 打招呼
- 打招呼
- Java Map
- CVP bug整理
- 【DBaas】如何使用Oracle Compute Cloud Service
- git冲突Please move or remove them before you can merge
- poj--3264 Balanced Lineup(RMQ)
- Android跟你打招呼
- 创建自定义对象的4种方法
- 数字图像处理MATLAB基础中的一些新发现
- EL表达式使用了java保留关键字
- 第二个MapReduce程序----flowcount(流量统计,自定义排序,自定义分区)
- ReactiveCocoa学习总结
- 更改win8.1的文档背景色
- Hadoop调优
- Java网络编程之NIO编程(待补充)