大家好,感謝您事先的任何答案。故障投訴次活動
的具有1M的問題是,我所謂的「Calander.class」第二個活動是不是從我的主要活動被稱爲所謂的「ShiftSelection」。林新編程和Android一般,我只是想學習的基本知識,但這個問題真的難倒我。 我已經加入了活動的清單文件,並覺得我正確地調用意圖,但運行我的按鈕的應用程序的onClick應該調用第二個活動不會做任何事情的時候。
我在做什麼錯?非常抱歉,如果這是一個簡單的答案,但我向你保證,我已經嘗試過許多個小時嘗試不同的事情並失敗了。
我的第一個活動,清單文件的代碼如下。
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;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class ShiftSelection extends Activity{
Button openButton;
RadioGroup shiftSelection;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.shiftselection);
shiftSelection = new RadioGroup(this);
RadioButton shiftPattern1 = new RadioButton(this); //shiftPattern1 = 4 shift
shiftPattern1.setText("4 shift");
shiftPattern1.setChecked(true);
shiftPattern1.setId(01);
RadioButton shiftPattern2 = new RadioButton(this); //shiftPattern2 = 6 shift
shiftPattern2.setText("4 shift");
shiftPattern2.setId(02);
shiftSelection.addView(shiftPattern1);
shiftSelection.addView(shiftPattern2);
Button openButton = new Button(this);
openButton.setText("open");
openButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Calander.class);
int genderID = shiftSelection.getCheckedRadioButtonId();
switch(genderID){
case 01:
intent.putExtra("shiftPattern", "1");
break;
case 02:
intent.putExtra("shiftPattern", "2");
break;
}
startActivity(intent);
}
});
}
}
而且清單文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.examples"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ShiftSelection"
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=".Calander">
</activity>
</application>
</manifest>
三江源的任何幫助。
嗨dymmeh,非常感謝您的時間和答案是現貨!我改變了我的代碼,並解決了這個問題,我很高興這是一個簡單的修復。我已經接受你的回答並標上了勾號,不確定是否還有其他事情可以投票給你? –