我创建了一个CalendarView
,只要您选择一个日期,就会打开一个新活动。在那个新活动中,我放了一个按钮和一个TextView
,我希望它TextView
显示一个字符串。问题是,当我选择一个日期时,会显示一条消息,上面写着“不幸的是,”project_name“已停止!”。
这是新活动的代码:
public class CalendarDate extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar_date);
Bundle extras = getIntent().getExtras();
String dday = extras.getString("currentday");
String dmonth =extras.getString("currentmonth");
String dyear = extras.getString("currentyear");
ActionBar ab = getActionBar();
ab.setTitle(dday+"/"+dmonth+"/"+dyear );
Bundle extraz =getIntent().getExtras();
String display = extras.getString("EXTRA_MESSAGE");
LinearLayout layout=(LinearLayout) this.findViewById(R.id.Layout);
EditText editText=(EditText) this.findViewById(R.id.textView);
Button button=(Button) this.findViewById(R.id.btnAdd);
LayoutParams lparams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText(display);
layout.addView(tv);
}
public void sceduleEdit(View view) {
Intent intent = new Intent(this, EditSc.class);
startActivity(intent);
}
}
这是XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="CalendarDate"
android:orientation="vertical"
android:id="@+id/Layout">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/btnAdd"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginBottom="34dp"
android:layout_marginLeft="88dp"
android:onClick="sceduleEdit" />
如果删除以下代码,则活动将按预期打开
LinearLayout layout=(LinearLayout) this.findViewById(R.id.Layout);
EditText editText=(EditText) this.findViewById(R.id.textView);
Button button=(Button) this.findViewById(R.id.btnAdd);
LayoutParams lparams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText(display);
layout.addView(tv);
你有什么想法为什么会这样?很抱歉这个问题很长,提前非常感谢!