任务一 HelloWorld
来源:互联网 发布:万游网络武汉 编辑:程序博客网 时间:2024/06/05 07:31
1.运行效果图
2.核心代码
package cn.edu.bzu.helloworld;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity {private Button btnClick;private EditText etName;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btnClick=(Button) findViewById(R.id.btnClick);btnClick.setOnClickListener(new ClickHandler());etName=(EditText) findViewById(R.id.etName);}class ClickHandler implements OnClickListener {public void onClick(View view) {String name=etName.getText().toString();Toast.makeText(MainActivity.this, "Hello "+name, Toast.LENGTH_LONG).show();}}}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg" > <EditText android:id="@+id/etName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="32dp" android:layout_marginTop="95dp" android:background="@android:drawable/edit_text" android:drawableLeft="@drawable/name" android:ems="10" android:hint="请输入你的姓名" /> <requestFocus/> <Button android:id="@+id/btnClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/handok" android:layout_centerHorizontal="true" android:layout_centerVertical="true" ></Button> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.edu.bzu.helloworld" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="cn.edu.bzu.helloworld.MainActivity"> <intent-filter > <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application></manifest>
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">HelloWorld</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <string name="etNameprompt">请输入你的姓名</string> </resources>
3.存在问题
在本次实验中,做不出点击之后出现的对话框中的笑脸。而且,在实验过程中遇到一些小问题之后细心研究录像,进而解决了问题。
做出实验效果,感觉很欣慰。
0 0
- 任务一 HelloWorld
- 初学Java,HelloWorld(一)
- servlet helloworld(一)
- Hibernate HelloWorld(一)
- Spring MVC (一) - HelloWorld
- SpringMVC入门一:helloWorld
- JNI学习(一)----helloworld
- 初学Java,HelloWorld(一)
- wayland helloworld (一)
- Akka 【一】 HelloWorld
- struts2 学习一 HelloWorld
- 实例一:HelloWorld
- C#(一) helloworld
- xfire基础一: helloworld
- cocos2d-JS (一)HelloWorld
- Hibernate--HelloWorld案例--(一)
- nasm教程一:helloworld
- spring(一)helloworld
- 聚类
- Linux的哲学思想
- hdu4221 Greedy?
- 深入浅出RxJava(二:操作符)
- 欢迎使用CSDN-markdown编辑器
- 任务一 HelloWorld
- OpenCV 图像线性滤波综合示例程序(用到了Trackbar轨迹条)
- _cinit
- Hibernate JAP 字段自动添加下划线问题,
- 基于c++标准库计算文件大小
- 第三章习题3-第6题==判断完数
- 滑动窗口机制
- 第三周 项目4-顺序表的应用
- PHP中echo和print的区别