我正在使用一个按钮来切换活动,但是logcat说我还没有在我的AndroidManifest.xml
中宣布我的活动至少检查了五次,而且它就在那里。
我试图切换到fahrenheittocelsius类。
带有按钮的主要java页面在这里:
package com.jordandebarth.supercalculator;
import com.jordandebarth.supercalculator.distance;
import com.jordandebarth.supercalculator.exponents;
import com.jordandebarth.supercalculator.nuclearfusion;
import com.jordandebarth.supercalculator.pythagorean;
import com.jordandebarth.supercalculator.fahrenheittocelsius;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.support.v4.app.NavUtils;
public class tab_view extends Activity {
Button calculator, pythagorean, distance, exponent, temperature, nuclearfusion;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tab_view);
calculator = (Button)findViewById(R.id.calculatorButton);
pythagorean = (Button)findViewById(R.id.pythagoreanButton);
distance = (Button)findViewById(R.id.distanceButton);
exponent = (Button)findViewById(R.id.exponentsButton);
temperature = (Button)findViewById(R.id.temperatureButton);
nuclearfusion = (Button)findViewById(R.id.nuclearfusion);
pythagorean.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent pythagoreanIntent = new Intent(getBaseContext(), pythagorean.class);
startActivityForResult(pythagoreanIntent, 0);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
distance.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent distanceIntent = new Intent(getBaseContext(), distance.class);
startActivityForResult(distanceIntent, 0);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
exponent.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent exponentIntent = new Intent(getBaseContext(), exponents.class);
startActivityForResult(exponentIntent, 0);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
temperature.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent temperatureIntent = new Intent(getBaseContext(), fahrenheittocelsius.class);
startActivityForResult(temperatureIntent, 0);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
nuclearfusion.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent nuclearfusionIntent = new Intent(getBaseContext(), nuclearfusion.class);
startActivityForResult(nuclearfusionIntent, 0);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
}
}
我的AndroidManifest是:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jordandebarth.supercalculator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".tab_view"
android:label="@string/title_activity_tab_view" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activty
android:name=".fahrenheittocelsius"
android:label="Fahrenheit to Celsius"
></activty>
<activity
android:name=".calculator"
android:label="Calculator" >
</activity>
<activity
android:name=".pythagorean"
android:label="Pythagorean Theorem"
>
</activity>
<activity
android:name=".distance"
android:label="Distance Formula"
></activity>
<activity
android:name=".exponents"
android:label="Exponents"
></activity>
<activity
android:name=".nuclearfusion"
android:label="Nuclear Fusion"
></activity>
</application>
</manifest>
答案 0 :(得分:0)
将getBaseContext()
的所有实例替换为tab_view.this
。
答案 1 :(得分:0)
startActivityForResult允许您启动活动并获取一些数据。想象一下,你有一些文件选择器活动。按照答案链接。而且,如果您使用startActivityForResult()
,则需要onActivityResult()
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Result OK.d.
if (requestCode == resultCode) {
// do something good
}
}
尝试使用以下代码开始您的活动 -
Intent temperature = new Intent(tab_view.this, fahrenheittocelsius.class);
startActivity(temperature);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);