简体   繁体   English

Hello World Android教程

[英]Hello World Android Tutorial

I am running the Hello World app successfully through an emulator (with Eclipse). 我通过模拟器(使用Eclipse)成功运行Hello World应用程序。 I have followed every step from the android website. 我已经关注了android网站的每一步。 The app runs and gives me the option to enter a String and click Send. 该应用程序运行并为我提供输入字符串的选项,然后单击发送。 Unfortunately, when I click send, nothing happens. 不幸的是,当我点击发送时,没有任何反应。 I have completed this app through the tutorial, and I have tried setting the message to something within the code, but no success. 我已经通过教程完成了这个应用程序,我尝试将消息设置为代码中的某些内容,但没有成功。 It is my best guess that DisplayMessageActivity.java is not running, because I have tried giving the message to be displayed a preset String, but have not been successful. 我最好猜测DisplayMessageActivity.java没有运行,因为我试图让消息显示一个预设的字符串,但是没有成功。 I know this is a fairly vague question, but I cannot seem to find the next step to solve this problem, hence the question. 我知道这是一个相当含糊的问题,但我似乎无法找到解决这个问题的下一步,因此问题。 Thanks! 谢谢! Let me know if you need to see any additional code; 如果您需要查看任何其他代码,请告诉我们; here is my code for MainActivity.java: 这是我的MainActivity.java代码:

package com.example.myfirstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
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.activity_main, menu);
//        return true;
//    }

    //** Called when the user clicks the Send button *
    public void sendMessage(View view){
        //Do something in response to the 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);
    }

}

You need to call startActivity (intent); 你需要调用startActivity (intent); from your sendMessage() . 来自你的sendMessage() Put it right before the closing brace. 把它放在关闭支架前面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM