public class ToastActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
DisplayToast("点击了OK按钮!");
}
});
}
private void DisplayToast(String string) {
Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
}
public boolean onTouchEvent(MotionEvent event){//添加触摸确定位置的事件
int iAction = event.getAction();
if(iAction==MotionEvent.ACTION_DOWN)
return false;
int X = (int) event.getX();
int Y = (int) event.getY();
DisplayToast("触到坐标:("+Integer.toString(X)+","+Integer.toString(Y)+")");
return super.onTouchEvent(event);
}
}
public class EditTextActivity extends Activity {
private TextView textView;
private EditText editText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView = (TextView) findViewById(R.id.textView1);
editText = (EditText) findViewById(R.id.editText1);