2013-03-11 2 views
0

도움이되는 제안에 감사드립니다. 프로젝트의 모양과 내가 얻은 빈 화면을 보여주고 싶기 때문에 초기 질문을 수정했습니다. 자습서가 표시되어야 함을 나타냅니다. 그 첫 번째 문제를 해결할 수 있었지만 (다만 일종의 문제였습니다), developer.android.com/training/에있는 기사의 두 번째 부분에서 설명한대로 첫 번째 의도를 작성한 후에 문제가 발생했습니다. 기본/firstapp/starting-activity.html # receivetheintentAndroid 개발자의 첫 번째 앱 자습서

프로젝트가 빌드되었지만 프로젝트에 대해 설정 한 실행 구성에 아래 코드에 나열된 입력 요소가 표시되지 않습니다. 문제를 해결하는 방법을 잘 모르며 추가 도움을 주시면 감사하겠습니다. 도움에 다시 한번 감사드립니다.

에뮬레이터 : http://s1278.beta.photobucket.com/user/cetmrw791346/media/1_zps116f17a9.png.html

패키지 탐색기 : http://s1278.beta.photobucket.com/user/cetmrw791346/media/2_zps0f2b94a2.png.html

그리고 여기가 관련 파일 : 콘솔 로그에서와

**AndroidManifest.xml** 


<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.firstapp" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="17" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.firstapp.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.firstapp.DisplayMessageActivity" 
      android:label="@string/title_activity_display_message" 
      android:parentActivityName="com.example.firstapp.MainActivity" > 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="com.example.firstapp.MainActivity" /> 
     </activity> 
    </application> 

</manifest> 


**MainActivity.java** 


package com.example.firstapp; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.View; 
import android.widget.EditText; 

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; 
    } 


    /** Called when the user clicks the 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); 
    } 
} 
activity_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" 
    tools:context=".MainActivity" > 
    <EditText android:id="@+id/edit_message" 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     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> 


**strings.xml** 


<?xml version="1.0" encoding="utf-8"?> 
<resources> 

    <string name="app_name">My First App</string> 
    <string name="edit_message">Enter a message</string> 
    <string name="button_send">Send</string> 
    <string name="menu_settings">Settings</string> 
    <string name="title_activity_main">MainActivity</string> 
    <string name="title_activity_display_message">DisplayMessageActivity</string> 
    <string name="action_settings">Settings</string> 
    <string name="hello_world">Hello world!</string> 

</resources> 

activity_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=".DisplayMessageActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" /> 

</RelativeLayout> 


**DisplayMessageActivity.java** 


package com.example.firstapp; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.support.v4.app.NavUtils; 
import android.annotation.TargetApi; 
import android.os.Build; 

public class DisplayMessageActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_display_message); 
     // Show the Up button in the action bar. 
     setupActionBar(); 
    } 

    /** 
    * 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); 
    } 

} 

답변

2

:

Error: No resource found that matches The given name (at 'title' with value '@string/action_settings')

평균 의 u는 res/values/strings.xml 파일 내부에 action_settings 문자열을 정의해야합니다 : 당신은 그럼 그냥 res/menu/main.xml 내부 android:title 항목 속성을 언급 귀하의 응용 프로그램에 대한 Menu을 사용하지 않는 경우

<resources> 
     <!-- Other String name- value --> 
    <string name="action_settings">Action Settings</string> 
</resources> 

와 두 번째 방법입니다. 메뉴 항목이 android:title보다는 title의 완전한 이름을 사용하지 않거나 당신이 그것을 사용하는 문자열을 정의하지 않은 것처럼

2

그것은에 대한 menu/main.xml을 불평하지 layout/activity_main.xml

보인다.

관련 문제