I follow the tutorial android official website made the first android app, but when you do the test found on my nexus4 phone program after completing the first activity can not enter the second activity. We want to help look great God, thank you!
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 class DisplayMessageActivity extends Activity { @ SuppressLint ("NewApi") @ Override
protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_display_message); / / Show the Up button in the action bar. setupActionBar (); if (Build.VERSION.SDK_INT> = Build.VERSION_CODES.HONEYCOMB) { getActionBar () setDisplayHomeAsUpEnabled (true);. } Intent intent = getIntent (); String message = intent.getStringExtra (MainActivity.EXTRA_MESSAGE);
TextView textView = new TextView (this); textView.setTextSize (40); textView.setText (message);
setContentView (textView); }
/ ** * Set up the {@ link android.app.ActionBar}, if the API is available. * / @ TargetApi (Build.VERSION_CODES.HONEYCOMB) private void setupActionBar () { if (Build.VERSION.SDK_INT> = Build.VERSION_CODES.HONEYCOMB) { getActionBar () setDisplayHomeAsUpEnabled (true);. } }
@ Override public boolean onOptionsItemSelected (MenuItem item) { switch (item.getItemId ()) { case android.R.id.home: / / This ID represents the Home or Up button. In the case of this / / Activity, the Up button is shown. Use NavUtils to allow users / / To navigate up one level in the application structure. For / / More details, see the Navigation pattern on Android Design: / / / / Http://developer.android.com/design/patterns/navigation.html # up-vs-back / / NavUtils.navigateUpFromSameTask (this); return true; } return super.onOptionsItemSelected (item); }
My First App Enter a message Send Settings MainActivity My Message
<-! Baidu Button BEGIN -> more Share to: <-! Baidu Button END ->
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) -> Reply: DisplayMessageActivity this you registered yet inside the AndroidManaifeset.xml Reply:
This has been registered, it is automatically added to the eclipse. Can not run android version and what relationship, the tutorial that their code is running on android4.0, I this is 4.3
android: name = "com.example.myfirstapp.DisplayMessageActivity" android: label = "@ string / title_activity_display_message" android: parentActivityName = "com.example.myfirstapp.MainActivity"> android: name = "android.support.PARENT_ACTIVITY" android: value = "com.example.myfirstapp.MainActivity" />
Reply: It does not matter what misstatements Reply:
DisplayMessageActivity this inside you AndroidManaifeset.xml registered yet
This has been registered, it is automatically added to the eclipse. Can not run android version and what relationship, the tutorial that their code is running on android4.0, I this is 4.3
android: name = "com.example.myfirstapp.DisplayMessageActivity" android: label = "@ string / title_activity_display_message" android: parentActivityName = "com.example.myfirstapp.MainActivity"> android: name = "android.support.PARENT_ACTIVITY" android: value = "com.example.myfirstapp.MainActivity" />
Reply: This is Consle output without error. Fat LogCat up to look at. Reply: setContentView (textView); Here it is dead. Reply: The setupActionBar (); commented try again. Reply: sendMessge (View v) did not call inside onCreate Reply:
sendMessge (View v) did not call
In onCreate inside
Yes, because wrong, it should be sendMessage (View view), now changed over, no problem. Thank you
No comments:
Post a Comment