HelloFormStuff .java 代码如下
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.ToggleButton;
public class HelloFormStuff extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton button = (ImageButton) findViewById(R.id.android_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
Toast.makeText(HelloFormStuff.this, "Beep Bop", Toast.LENGTH_SHORT).show();
}
});
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
if (checkbox.isChecked()) {
Toast.makeText(HelloFormStuff.this, "Selected", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(HelloFormStuff.this, "Not selected", Toast.LENGTH_SHORT).show();
}
}
});
View.OnClickListener radio_listener = new View.OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(HelloFormStuff.this, rb.getText(), Toast.LENGTH_SHORT).show();
}
};
final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
radio_red.setOnClickListener(radio_listener);
radio_blue.setOnClickListener(radio_listener);
final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
togglebutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
if (togglebutton.isChecked()) {
Toast.makeText(HelloFormStuff.this, "ON", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(HelloFormStuff.this, "OFF", Toast.LENGTH_SHORT).show();
}
}
});
}
}
layout->main.xml
<?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" >
<ImageButton
android:id="@+id/android_button"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:src="@drawable/android" />
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<CheckBox android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="check it out" />
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red" />
<RadioButton android:id="@+id/radio_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blue" />
</RadioGroup>
<ToggleButton android:id="@+id/togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
run it 结果如下:
![](http://androidappdocs.appspot.com/guide/tutorials/views/images/hello-formstuff.png)
分享到:
相关推荐
Eclipse开发android应用
Eclipse 开发 android 应用Eclipse 开发 android 应用
Eclipse开发android教程Eclipse开发android教程
NULL 博文链接:https://llhdf.iteye.com/blog/521272
Eclipse 开发 Android 应用程序 Android 是一种针对移动平台的开放源码操作系统, Google 引入了 Android,并在短时间内获得了市场的关注。 Android 不仅仅是另一种包含电话、菜单和触摸屏功能的移动平台,而是一种...
详细介绍了在eclipse中android项目下c/c++代码的自动编译,和在eclipse中用ant生成ndk需要的jni头文件,加速ndk的开发,因为是原创,费了不少心力和时间,所以设了6分,有人反映太贵了,现在调成3分,这下大家满意了...
eclipse如何开发Android:程序下载、环境安装配置
Eclipse搭建Android开发环境及新建 新手必备
Eclipse开发Android应用程序入门
本教程介绍如何在 Eclipse 环境中进行 Android 应用程序开发,包括两个示例应用程序。第一个示例是一个基本的应用程序,涉及构建和调试的所有阶段。第二个应用程序示例涉及比较复杂的 Android 特性,包括联系人搜索...
eclipse部署android开发环境,详细介绍如何在eclipse中配置android开发环境,一步一步介绍,内容详细,值得下载
Android开发环境搭建全程演示(jdk+eclipse+android sdk)
NULL 博文链接:https://llhdf.iteye.com/blog/521201
Eclipse NDK 开发之 HelloWorld。 详细说明,见相关博客。
Eclipse开发学习笔记。感觉挺好的,就传上来给大家共享
NULL 博文链接:https://llhdf.iteye.com/blog/521283
eclipse开发安卓的必须插件 ADT 自己使用很完美上传共享给大家
Android源码支持多种IDE,如果是针对APP层做开发的话,建议大家使用Eclipse开发环境。在源码路径(~/development/ide/eclipse)下,Android提供了.classpath配置文件
Eclipse实现更改Android的状态栏颜色
eclipse开发的android平台的用于文件加密的小软件。分为对称加密、报文鉴别、数字签名等功能。仅作为android开发的小例子供参考,做得比较简陋。