一个Android程序 Helloworld

HelloActivity.java

 

package mars.helloworld;

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

public class HelloActivity extends Activity {
 private Button myButton1 = null;
 private Button myButton2 = null;
 private TextView myEditText = null;
 private TextView myTextView = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);//设置Activity的布局
        myButton1 = (Button)findViewById(R.id.myButton1);//得到按钮对象s
        myButton2 = (Button)findViewById(R.id.myButton2);
        myEditText = (TextView)findViewById(R.id.myEditText);//得到TextView对象
        myTextView = (TextView)findViewById(R.id.myTextView);
        myButton1.setOnClickListener(new View.OnClickListener() {//给按钮注册监听器
   
   public void onClick(View v) {
    myTextView.setText(myEditText.getText());
   }
  });
        myButton2.setOnClickListener(new View.OnClickListener() {
   
   public void onClick(View v) {
    myTextView.setText(new String());
   }
  });
       
    }
}

 

 

AndroidManifest.xml

 

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="mars.helloworld"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

 

 

main.xml

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<EditText 
 android:id="@+id/myEditText"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
    />
<Button
 android:id="@+id/myButton1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/myButtonText1"
 />
<Button
 android:id="@+id/myButton2"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/myButtonText2"
 />
<TextView 
 android:id="@+id/myTextView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
</LinearLayout>

 

 

strings.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, HelloActivity!</string>
    <string name="app_name">helloworld</string>
    <string name="myButtonText1">Click Button One</string>
    <string name="myButtonText2">Click Button Two</string>
</resources>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值