나는이 같은 활동의 텍스트 뷰에 메시지를 표시하려고 : "안녕하세요!"안드로이드 텍스트 뷰의 setText는 문제
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Get the message from the intent
Intent intent = getIntent();
// Create the text view
TextView textView = (TextView) findViewById(R.id.display_message);
if(intent.getExtras() != null){
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
textView.setTextSize(40);
textView.setText(message);
}else{
textView.setTextSize(40);
textView.setText(R.string.hello_world);
}
// Show the Up button in the action bar.
setupActionBar();
}
표시되어있는 코드를 intent
에 포함 된 추가 메시지가 null
인데 그 대신 hello world!
이 표시되지 않았습니다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Action Bar</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
</resources>
메시지를 보내 주요 활동 : "안녕하세요!"
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);
}
@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_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
//return true;
}
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);
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_search:
// openSearch();
return true;
case R.id.action_settings:
// openSettings();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
내가 메시지 – daiyue
intent.getExtras를 보내는 책임이 주요 활동에 대한 코드를 추가 한 의미하지 않는다 너무 – njzk2