Android:使用按钮事件切换到另一个活动?

dez*_*cus 1 android android-button

我想使用按钮将当前活动更改为android中的另一个活动.但是,每当我单击该按钮时,eclipse调试透视会出现错误"source not found".这是我用来改变活动的功能

public void toManager(){
    Intent i = new Intent(getApplicationContext(), DegreeActivity.class);
    startActivity(i);
}
Run Code Online (Sandbox Code Playgroud)

在我的xml文件中,该按钮具有onClick侦听器.这是xml

<Button
    android:id="@+id/btn_toDegree"
    android:text="@string/btn_toDegree"
    android:textSize="13pt"
    android:layout_centerVertical="true"
    android:gravity="center"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:layout_marginLeft="15dip"
    android:layout_marginRight="15dip"
    android:onClick="toManager"  <!-- This line -->
    />  
Run Code Online (Sandbox Code Playgroud)

如果我在第一个活动toManager()onCreate()块中调用该函数,它将切换到下一个没有错误的活动.但是,当我尝试使用按钮切换时,它不起作用.

Mic*_*ael 7

Click handler必须如下所示:

public void toManager(View view) {
    Intent i = new Intent(getApplicationContext(), DegreeActivity.class);
    startActivity(i);
}
Run Code Online (Sandbox Code Playgroud)

来自Button文档:

现在,当用户单击该按钮时,Android系统会调用活动的selfDestruct(View)方法.为了使其工作,该方法必须是公共的并且接受a View作为其唯一参数.