첫 번째 활동은 사용자가 3 개의 단추 중 하나를 클릭하도록 요청하므로 각 단추는 색상을 나타냅니다. 두 번째 액티비티를 만들고 클릭 한 버튼의 가치를 수용했습니다. 단추의 값이 색상과 일치하면 if 루프를 사용하여 "사용자가 선택한 (색상)"문자열을 표시해야합니다. 그러나, 나는 의도 객체를 통해 전달한 매개 변수에 대해 확신하지 못합니다. 누구든지 도와 줄 수 있습니까? 그리고 그래, 난 멍청이야, 그냥 안드로이드를 배우기 시작했다.두 번째 활동에 텍스트를 표시하는 방법
package org.example.helloandroid;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
String EXTRA_MESSAGE= null;
@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 the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void gotoActivity(View v) {
Button b= (Button)v;
String message= b.getText().toString();
if (message=="red") {
Intent intent = new Intent(this, ColorActivity.class);
intent.putExtra(EXTRA_MESSAGE, "You have chose RED ");
startActivity(intent);
}
if (message=="green") {
Intent intent= new Intent(this, ColorActivity.class);
intent.putExtra(EXTRA_MESSAGE, "You have chose GREEN!");
startActivity(intent);
}
else {
Intent intent= new Intent (this, ColorActivity.class);
intent.putExtra(EXTRA_MESSAGE, "You have chose BLUE");
startActivity(intent);
}
}
} 여기
은 다음과 같이 두 번째 활동 확인 번째 활동 -의 ColorActivity
package org.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class ColorActivity extends Activity {
String EXTRA_MESSAGE= "message";
TextView mTextview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.color_activity);
mTextview=(TextView) findViewById(R.id.textView1);
mTextview.setText(getIntent().getStringExtra("EXTRA_MESSAGE"));
}
}
입력 해 주셔서 감사합니다.하지만 첫 번째 활동에서 아무 버튼을 클릭해도 텍스트가없는 빈 활동이 표시됩니다. 하지만 당신의 도움에 감사드립니다. – user3722881