Android 개발에 처음 나올 때 Google을 통해 도움을 얻을 수 없습니다. 제 대답을 누군가 찾을 수 있으면 용서하세요.Android 활동이 자동으로 시작됩니다 - 원하지 않음
I'm working on this tutorial 그리고 나는 그 끝 부분을 보았고, 자그마한 꼬임을 다루었 기 때문에 자습서가 그들의 IDE에 최신이 아닙니다. 무언가를 입력하고 보내기 버튼을 누른 다음 새로운 텍스트보기로 구성된 새로운 활동을 시작하고 그 메시지 만 표시 할 수있는 간단한 텍스트 상자가 있어야합니다.
에뮬레이터에서 응용 프로그램을 컴파일하고 실행하면 자동으로 두 번째 활동이 자동으로 시작되고 기본 "Hello World!"가 표시됩니다. 문자열 대신 내 텍스트 상자를 가져오고 시작 버튼을 보냅니다. 두 번째 액티비티를 포함시키고 인 텐트 기능을 사용하기 전에 텍스트 상자와 버튼이 있었기 때문에 입력을하기 전에 새로운 액티비티를 자동으로 시작한다고 생각합니다. 누군가가 왜 그런지 말할 수 있습니까?
필자는 코드를 복사/붙여 넣기하여 오타가 없게 만들었습니다. 내 activity_main.xml 파일은 실제로 새 활동을 호출하는 메소드를 시작하기 전에 "onClick"을 지정하므로, 내가 다른 곳에서 잘못된 일을하고 있는지 또는 튜토리얼의 불일치로 인한 것인지 확실하지 않습니다.
관련 참고 자료에서 자습서가 안드로이드 개발을위한 학습을 시작하는 데 이상적인 방법이 아니라면 제안이나 올바른 방향으로의 포인트를 좋아할 것입니다. 미리 감사드립니다. 여기
<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="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".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=".DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
는 MainActivity.java 파일입니다 :
여기 내 매니페스트 코드의 패키지 com.example.myfirstapp; 여기
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
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_display_message);
}
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void sendMessage(View view) {
// Do something in response to button
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);
}
}
는 DisplayMessageActivity.java 파일입니다 : 패키지 com.example.myfirstapp;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class DisplayMessageActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.display_message, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
어디에서 sendMessage() 메서드를 호출하고 있습니까? –
솔직히, 귀하의 설명과 귀하의 코드를 기반으로 어떤 문제도 찾을 수 없습니다. 새 프로젝트를 만들고 자습서를 다시 실행할 수 있습니까? 또한 새로운 프로젝트를 실행하기 전에 관련이없는 모든 프로젝트를 닫으십시오 ('support-v7'을 제외한 모든 프로젝트가 종료되어야합니다). –
나는 내일 그것을해야 할 것이다, 나는 오늘 밤 그것에 일할 시간이 없다. 직업과 가족은 제가 할 수있는 많은 시간을두고 있습니다. 그러나 그것은 고무적입니다. 내일 다시하고 다시 보겠습니다. 고맙습니다! – M4v