我尝试在同一页面上搜索多种利用多个按钮的方法。我可以得到第一个按钮,但第二个和第三个按钮强制关闭。有谁知道为什么会这样?我认为它可能是语法 - 但我可能是错的,因为我是新手。提前谢谢。
主Java:
package com.pangolin.rollin.ts;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class TeamSupport extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_team_support);
Button wireless=(Button)findViewById(R.id.button_wireless);
Button tools=(Button)findViewById(R.id.button_tools);
Button about=(Button)findViewById(R.id.button_about);
wireless.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myintent1 = new Intent(TeamSupport.this,Wireless.class);
startActivity(myintent1);
}
});
tools.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myintent2 = new Intent(TeamSupport.this,Tools.class);
startActivity(myintent2);
}
});
about.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myintent3 = new Intent(TeamSupport.this,About.class);
startActivity(myintent3);
}
});
}
}
主XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/make_selection"
android:textColor="#3F9BBF" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView3"
android:layout_centerHorizontal="true"
android:text="@string/beta_notice"
android:textColor="#3F9BBF" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/credits"
android:textColor="#3F9BBF" />
<Button
android:id="@+id/button_wireless"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:text="@string/button_wireless"
android:textColor="#3F9BBF" />
<Button
android:id="@+id/button_tools"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/button_wireless"
android:text="@string/button_tools"
android:textColor="#3F9BBF" />
<Button
android:id="@+id/button_about"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/button_tools"
android:text="@string/button_about"
android:textColor="#3F9BBF" />
</RelativeLayout>
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pangolin.rollin.ts"
android:installLocation="auto"
android:versionCode="1"
android:versionName="Beta 0.1" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".TeamSupport"
android:label="@string/title_activity_team_support" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Wireless"
android:label="@string/title_activity_wireless"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".About"
android:label="@string/title_activity_about"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name=".Tools"
android:label="@string/title_activity_tools"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
答案 0 :(得分:2)
您只需实现OnClickListener。
now tools.setOnClickListener(this);
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.R.id.button_wireless:
Intent myintent1 = new Intent(TeamSupport.this,Wireless.class);
startActivity(myintent1);
break;
}
请尝试这样做更好,占用记忆更少。
答案 1 :(得分:1)
删除以下代码
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
来自manifest.xml的
无线,关于和工具活动代码