I start a new activity when clicking on a button , but the content(ui components) of the new activity doesn't appear , why ??
button listener to start new activity
m_sendButton.setOnClickListener(
new OnClickListener(){
public void onClick(View view) {
Intent in = new Intent(context, 开发者_Python百科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 (just for test)
<?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>
You have a typo in your onCreate method. The method name says onCreat - it's missing an '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);
}
}
In general it's useful to use the @Override
annotation to help you catch any mistakes such as this. If the parent class does not have a matching method signature then your IDE (at least Eclipse does this) will warn you or present an error.
精彩评论