Android 如何使用安卓:onClick?
我是android编程新手。如何使用安卓:onClick?我将要调用的方法放在哪里Android 如何使用安卓:onClick?,android,onclicklistener,Android,Onclicklistener,我是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" andr
<?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" />
我是否将它放在调用此布局的.java文件中?是的,您需要将它放在设置ContentView此布局的activity类中。 onclick的方法应采用以下形式:
public void doSomething(View v) {
}
是的,您需要将其放在设置ContentView此布局的activity类中。 onclick的方法应采用以下形式:
public void doSomething(View v) {
}
我想你已经解决了如何在活动中设置内容?在同一活动中,添加:
public void doSomething( View view ) {
// onClick code goes here.
}
我想你已经解决了如何在活动中设置内容?在同一活动中,添加:
public void doSomething( View view ) {
// onClick code goes here.
}
是的,我已经解决了如何设置内容。谢谢你的回复。是的,我已经解决了如何设置内容的问题。谢谢你的回复。这很有帮助。谢谢,这正是我要找的。谢谢,这正是我要找的。