重點在以下二段
android:onClick
=
"onClick"
public void onClick(View view){
Toast.makeText(AndroidOnClickActivity.this,
"Button Clicked", Toast.LENGTH_LONG).show();
}
以下附較完整的程式碼:
android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" > < TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "@string/hello" /> < Button android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Click Me" android:onClick = "onClick" /> </ LinearLayout > |
package
com.AndroidOnClick;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Toast;
public
class
AndroidOnClickActivity
extends
Activity {
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public
void
onClick(View view){
Toast.makeText(AndroidOnClickActivity.
this
,
"Button Clicked"
, Toast.LENGTH_LONG).show();
}
}
全站熱搜