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 结果如下:

更多相关文章

  1. Delphi XE5 android 获取网络状态
  2. android 拖动图片移动效果
  3. Android(安卓)浅析 ButterKnife (一) 使用
  4. android打开联系人的代码
  5. org.gradle.api.GradleException: Lint found fatal errors whil
  6. Android重启应用程序代码
  7. Android基础之Android的Activity周期
  8. Android(安卓)手机获取时区
  9. 获取Android系统程序信息

随机推荐

  1. Android(安卓)项目优化(七):阿里巴巴Android
  2. 浅析Android手机卫士之手机实现短信指令
  3. 解决Gradle DSL method not found: ‘and
  4. Android(安卓)设置横屏模式显示
  5. 一样的Android,不一样的学习
  6. Android(安卓)统计图表引擎AChartEngine(
  7. Android(安卓)UI设计模式实例代码
  8. Android零基础入门
  9. ch017 Android(安卓)样式与主题
  10. android:id="@*android:id/seekbar" 注意