sys*_*out 14
查看此Android按钮教程; 这个简单的例子创建一个关闭按钮.
你需要做的就是:
1.将Button小部件添加到您的布局
<Button android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/title_close" />
Run Code Online (Sandbox Code Playgroud)
2.将setOnClickListener方法附加到按钮实例:
protected void onCreate(Bundle savedInstanceState) {
this.setContentView(R.layout.layoutxml);
this.closeButton = (Button)this.findViewById(R.id.close);
this.closeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
Run Code Online (Sandbox Code Playgroud)
动态:
Button btn= new Button(this);
btn.settext("Submit");
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
//your write code
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52493 次 |
| 最近记录: |