Hello i started learning android from that site Starting Another Activity | Android Developers
and whati did doesnt working.
here is the files
activity_main XML
MainActivity:
Another
and the manifest
When i am pushing send buttton the program get terminated and i dont know why
please help me.
and whati did doesnt working.
here is the files
activity_main XML
PHP:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="horizontal"
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=".MainActivity" >
<EditText
android:id="@+id/content"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:onClick="SendMessage"/>
</LinearLayout>
PHP:
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void SendMessage(View view)
{
Intent i = new Intent (this,Another.class);
EditText t = (EditText) findViewById(android.R.id.content);
String s = t.getText().toString();
i.putExtra(EXTRA_MESSAGE, s);
startActivity(i);
}
PHP:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
String s = i.getStringExtra(MainActivity.EXTRA_MESSAGE);
setContentView(R.layout.activity_another);
TextView t = new TextView(this);
t.setTextSize(40);
t.setText(s);
setContentView(t);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.another, menu);
return true;
}
PHP:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.first"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.first.MainActivity"
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="com.example.first.Another"
android:label="@string/title_activity_another" >
</activity>
</application>
</manifest>
please help me.