我无法从按钮启动活动我有4个按钮和4个活动?

时间:2014-08-13 15:15:02

标签: android button android-activity onclicklistener

请帮我解释如何开展其他活动

主要活动

package my.apps.news;

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

Button btn1,btn2,btn3,btn4;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


btn1 = (Button)findViewById(R.id.crazyworldview_button);
btn2 = (Button)findViewById(R.id.wordpress_button);
btn3 = (Button)findViewById(R.id.itsourplanet_button);
btn4 = (Button)findViewById(R.id.carsandbike_button);



btn1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, Blogger.class);
startActivity(intent);
}
});

btn2.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, Wordpress.class);
        startActivity(intent);
    }
});     

btn3.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, Itsourplanet.class);
startActivity(intent);
}
});

btn4.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, Carsandbikes.class);
startActivity(intent);
}
});


}
}

这是我的布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}" >

<Button 
android:id="@+id/crazyworldview_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/crazyworldview"
android:layout_margin="5dp"
android:onClick="crazyclick"/>
<Button android:id="@+id/wordpress_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/wordpress"
android:layout_margin="5dp"
android:onClick="wordclick"/>
<Button android:id="@+id/itsourplanet_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/itsourplanet"
android:layout_margin="5dp"
android:onClick="planetclick"/>
<Button  android:id="@+id/carsandbike_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/carsandbikes"
android:layout_margin="5dp"
android:onClick="carsclick"/>

</LinearLayout>

这是我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.apps.news"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="21" />
<uses-permission android:name="android.premission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Blogger"></activity>
<activity android:name=".Wordpress"></activity>
<activity android:name=".Itsourplanet"></activity>
<activity android:name=".Carsandbikes"></activity>
</application>

</manifest>

我无法使用按钮启动活动我的应用程序中有四个按钮和四个活动。我在其他布局中使用了webview

告诉我如何开始活动。提前谢谢你

0 个答案:

没有答案