简体   繁体   English

android 你好世界应用帮助

[英]android hello world app help

i am learning android apps and i made this app and it doesnt work我正在学习 android 应用程序,我制作了这个应用程序,但它不起作用

  package com.android.test;

  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.Toast;

  public class HelloWorld extends Activity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Button button = (Button) findViewById(R.id.Button01);
          button.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(HelloWorld.this, "Hello World", Toast.LENGTH_SHORT).show();
              }
          });
      }
  }

but it doesnt work!!!但它不起作用! please tell me what is wrong and help me to solve it!1请告诉我出了什么问题并帮助我解决它!1

Change the toast line to as follows:将 toast 行更改为如下:

Toast.makeText(getApplicationContext(), "Hello World", Toast.LENGTH_SHORT).show();

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

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