我知道还有其他类似的帖子,但没有一个有适合我的解决方案。
代码:http://pastebin.com/LSC3eH8p 回购:https ://github.com/josiah14/FuelConsumptionTutorial
当我单击按钮时,ConsCalc 活动中添加记录按钮的 OnClick 事件未触发。起初我认为这是一个热插拔问题,但我在最后 2 次测试之间完全卸载了该应用程序,并且回调仍然没有被触发。这里发生了什么?
public class AddRecord extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_record);
// Show the Up button in the action bar.
// getActionBar().setDisplayHomeAsUpEnabled(true);
}
public class CalcMenu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calc_menu);
// create a button object
final Button buttonAddRecord = (Button) findViewById(R.id.buttonAddRecord);
// attach a listener to the button
buttonAddRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// create an Intent object for this activity, including its destination class
Intent myIntent = new Intent(CalcMenu.this, AddRecord.class);
// run the activity
startActivity(myIntent);
}
});
和清单...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="idig.za.net.conscalc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="idig.za.net.conscalc.GetRegistration"
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="idig.za.net.conscalc.SplashScreen" >
</activity>
<activity android:name="idig.za.net.conscalc.CalcMenu" >
</activity>
<activity android:name="idig.za.net.conscalc.SearchRecord" >
</activity>
<activity android:name="idig.za.net.conscalc.AddRecord">
</activity>
</application>
</manifest>