SayHello
来源:互联网 发布:淘宝口令生成器 编辑:程序博客网 时间:2024/05/19 23:01
1.activity_main.xml
<LinearLayout 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:orientation="vertical"
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:gravity="center"
android:background="@drawable/bg"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/prompt" />
<EditText
android:id="@+id/name"
android:layout_width="198dp"
android:layout_height="wrap_content"
android:inputType="text"
android:textSize="20sp" />
<Button
android:id="@+id/clickButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/click" />
</LinearLayout>
2.MainActivity.java
package cn.bzu.sayhello;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button clickButton;
private EditText nameText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
clickButton = (Button) findViewById(R.id.clickButton);
nameText = (EditText) this.findViewById(R.id.name);
//绑定事件源和事件处理者 委托处理
clickButton.setOnClickListener(new ClickHandler());
}
//事件处理类
private class ClickHandler implements OnClickListener {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,
"你好" + nameText.getText().toString(), Toast.LENGTH_LONG)
.show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
- SayHello
- SayHello
- sayhello
- Sayhello
- py wx sayhello.
- 第一章SayHello程序
- java.lang.UnsatisfiedLinkError:sayHello()
- 分布式计算互相sayhello
- android小程序-----SayHello
- SayHello界面的编辑
- dubbo sayHello例子
- Android第一个应用程序:SayHello
- 一个简单的应用程序iphone : sayHello
- Android入门-SayHello及其多种实现方法
- Android入门-SayHello实现页面跳转
- 以SayHello为例说明三种事件处理方式
- JNI开发入门教程之sayHello(Xubuntu Linux OpenJDK7 Eclipse GCC)
- dwr3框架学习笔记–第一个dwr3程序sayhello
- 多层 UI 触摸事件的轻量级设计
- android解析XML文件的3种方式(其二)
- oracle经典面试题
- 建议的程序员学习LDA算法的步骤
- 浅议消息中间件技术标准与开源实现
- SayHello
- 架构设计:生产者/消费者模式
- UIImage
- 大话js代码静态检查
- WebSphere Log4j 配置
- 几种任务调度的 Java 实现方法与比较
- 正则表达式速查表
- 动态规划 最长公共子序列
- Linux利用Grub修改管理员密码