大家好,感谢您事先的任何答案。故障投诉次活动
的具有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,非常感谢您的时间和答案是现货!我改变了我的代码,并解决了这个问题,我很高兴这是一个简单的修复。我已经接受你的回答并标上了勾号,不确定是否还有其他事情可以投票给你? –