Jor*_*tle 1 android onclicklistener
我是android编程的新手.你如何使用android:onClick?我在哪里放置我想要的方法?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button"
android:onClick="doSomething"/>
<ImageView
android:id="@+id/icon"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="@drawable/molecule" />
Run Code Online (Sandbox Code Playgroud)
我会把它放在调用这个布局的.java文件中吗?
是的,你需要将它放在setContentView这个布局的活动类中.onclick的方法应该是这样的:
public void doSomething(View v) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2721 次 |
| 最近记录: |