在Android上更改活动

时间:2014-01-14 21:21:07

标签: android button android-activity pressed

我在论坛上看到了一些帖子,但它们对我不起作用......

我在Main中有两个按钮,我希望每个按钮在按下时打开另一个按钮...

这是我的代码:

在单击一个按钮的代码中:

public void onClick(View v)
{
switch (v.getId()) {
    case R.id.button1:
        Intent intent = new Intent(this, Pessoais.class);
        startActivity(intent);
         break;

    case R.id.button2:
        Intent intentC = new Intent(this, Corporativas.class);
        startActivity(intentC);
        break;
    }
}

这是我在XML文件中的按钮代码:

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/button1"
    android:layout_marginTop="25dp"
    android:onClick="onClick"
    android:text="Ligações Corporativas" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="42dp"
    android:onClick="onClick"
    android:text="Ligações Pessoais" />

这就是我在AndroidManifest(活动名称)上的内容:

<activity android:name=".Corporativas"></activity>
<activity android:name=".Pessoais" ></activity>

有人可以说出这里有什么问题或错过了吗?

当我点击一个按钮时,程序停止......出现一个消息框:“不幸的是,app停止了”

由于

1 个答案:

答案 0 :(得分:1)

出于某种原因,尽管您已在AndroidManifest中声明了您的活动,但它并不匹配。我建议您尝试在AndroidManifest名称中输入您的包的全名,所以:com.leucotron.caroline.Pessoais

相关问题