点击按钮时我开始新活动,但新活动的内容(ui组件)没有出现,为什么?
button listener to start new activity
m_sendButton.setOnClickListener(
new OnClickListener(){
public void onClick(View view) {
Intent in = new Intent(context, SendMessageForm.class);
// i.putExtra("id","4");
context.startActivity(in);
//Toast toast = Toast.makeText(context, "Error. Please try again later", Toast.LENGTH_SHORT);
//toast.show();
} }
);
SendMessageForm.java
import android.app.Activity;
import android.os.Bundle;
public class SendMessageForm extends Activity {
public void onCreat(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_result_form);
}
}
search_result_form.xml(仅供测试)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Send" android:id="@+id/btnBacksds"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
答案 0 :(得分:4)
你的onCreate方法中有一个拼写错误。方法名称是onCreat - 它缺少'e':
import android.app.Activity;
import android.os.Bundle;
public class SendMessageForm extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_result_form);
}
}
一般来说,使用@Override
注释帮助您发现任何错误都很有用。如果父类没有匹配的方法签名,那么您的IDE(至少Eclipse会这样做)会警告您或出现错误。