java - Android my first app doesnt start second activity -
java - Android my first app doesnt start second activity -
i want start larn how create android programme , i've started next official android tutorial. according tutorial when send button pressed, sec activity has been started , show written message.however in case, sec screen not opened. me why not working.
while trying solve problem, i've restarted eclipse , windows, i've started new project , i've copied website project.but whatever did, none of them solution problem.
here files :
mainactivity.java
package com.example.myfirstapp; import android.content.intent; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v7.app.actionbaractivity; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.edittext; public class mainactivity extends actionbaractivity { public final static string extra_message = "com.example.myfirstapp.message"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()) .commit(); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } /** called when user clicks send button */ public void sendmessage(view view) { intent intent = new intent(this, displaymessageactivity.class); edittext edittext = (edittext) findviewbyid(r.id.edit_message); string message = edittext.gettext().tostring(); intent.putextra(extra_message, message); startactivity(intent); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); homecoming rootview; } } } fragment_main.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:orientation="horizontal" > <edittext android:id="@+id/edit_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send" android:onclick="sendmessage" /> </linearlayout> androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="8" android:targetsdkversion="19" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name="com.example.myfirstapp.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.myfirstapp.displaymessageactivity" android:label="@string/title_activity_display_message" android:parentactivityname="com.example.myfirstapp.mainactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.example.myfirstapp.mainactivity" /> </activity> </application> </manifest> displaymessageactivity.java
package com.example.myfirstapp; import android.content.intent; import android.os.bundle; import android.support.v4.app.fragment; import android.support.v7.app.actionbaractivity; import android.view.layoutinflater; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.textview; public class displaymessageactivity extends actionbaractivity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // message intent intent intent = getintent(); string message = intent.getstringextra(mainactivity.extra_message); // create text view textview textview = new textview(this); textview.settextsize(40); textview.settext(message); // set text view activity layout setcontentview(textview); } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } /** * placeholder fragment containing simple view. */ public static class placeholderfragment extends fragment { public placeholderfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_display_message, container, false); homecoming rootview; } } } fragment_display_message.xml
<relativelayout 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="com.example.myfirstapp.displaymessageactivity$placeholderfragment" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </relativelayout> strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">my first app</string> <string name="edit_message">enter message</string> <string name="button_send">send</string> <string name="action_settings">settings</string> <string name="title_activity_main">mainactivity</string> <string name="title_activity_display_message">my message</string> <string name="hello_world">hello world!</string> </resources> java android mobile
Comments
Post a Comment