package com.jack.check;
import android.accounts.Account;
import android.accounts.OnAccountsUpdateListener;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.method.KeyListener;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class CheckActivity extends Activity {
private EditText myEdit1,myEdit2;
private CheckBox cb1;
private Button b1,b2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myEdit1=(EditText)findViewById(R.id.EditText01);
myEdit2=(EditText)findViewById(R.id.EditText02);
cb1=(CheckBox)findViewById(R.id.CheckBox01);
b1=(Button)findViewById(R.id.Button01);
b2=(Button)findViewById(R.id.Button02);
myEdit1.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// TODO Auto-generated method stub
myEdit1.setText("");
return false;
}
});
myEdit2.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// TODO Auto-generated method stub
myEdit2.setText("");
return false;
}
});
myEdit1.setOnFocusChangeListener(new OnFocusChangeListener()
{
public void onFocusChange(View v, boolean hasFocus)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), myEdit1.getText(),Toast.LENGTH_LONG );
}
});
myEdit2.setOnFocusChangeListener(new OnFocusChangeListener()
{
public void onFocusChange(View v, boolean hasFocus)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), myEdit1.getText(), Toast.LENGTH_LONG);
}
});
cb1.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), cb1.isChecked()+"", Toast.LENGTH_LONG);
}
});
b1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), b1.getText(), Toast.LENGTH_LONG);
}
});
b2.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), b2.getText(), Toast.LENGTH_LONG);
}
});
}
}
·····························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"
>
<TableLayout
android:id="@+id/TableLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名称"
/>
<EditText
android:id="@+id/EditText01"
android:text="admin"
android:layout_width="fill_parent"
android:scrollHorizontally="true"
/>
</TableRow>
<TableRow >
<TextView
android:id="@+id/TextView02"
android:text="用户密码"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/EditText02"
android:text="123"
android:password="true"
android:layout_width="fill_parent"
android:scrollHorizontally="true"
/>
</TableRow>
<TableRow >
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="自动登录"
/>
<CheckBox
android:text="check"
android:id="@+id/CheckBox01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow android:gravity="right" >
<Button
android:id="@+id/Button01"
android:text="登录"
/>
<Button
android:id="@+id/Button02"
android:text="取消"
/>
</TableRow>
</TableLayout>
</LinearLayout>