实验一-Android开发环境搭建与Hello-world_第1页
实验一-Android开发环境搭建与Hello-world_第2页
实验一-Android开发环境搭建与Hello-world_第3页
实验一-Android开发环境搭建与Hello-world_第4页
实验一-Android开发环境搭建与Hello-world_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验一Android开发环境搭建与Helloworld一、实验目的学会搭建并安装Android开发环境,并实现HelloWorld应用开发。主要仪器设备及套数计算机三、实验内容搭建开发环境;安装JavaJDK,下载Eclipse,解压Eclipse;官方下安装ADT(AndroidDevelopmentTools);安装Android;安装手机USB驱动;建立新项目,实现HelloWorld程序代码packagecom.example.helloandroid;importandroid.support.v7.app.ActionBarActivity;importandroid.os.Bundle;importandroid.view.Menu;importandroid.view.MenuItem;publicclassMainActivityextendsActionBarActivity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override publicbooleanonCreateOptionsMenu(Menumenu){ //Inflatethemenu;thisaddsitemstotheactionbarifitispresent. getMenuInflater().inflate(R.menu.main,menu); returntrue; } @Override publicbooleanonOptionsItemSelected(MenuItemitem){ //Handleactionbaritemclickshere.Theactionbarwill //automaticallyhandleclicksontheHome/Upbutton,solong //asyouspecifyaparentactivityinAndroidManifest.xml. intid=item.getItemId(); if(id==R.id.action_settings){ returntrue; } returnsuper.onOptionsItemSelected(item); }}实验结果六、实验小结这个实验很简单,主要是要我们学习Android开发环境的搭建,了解Android应用开发程序的开发过程,生成Android应用程序框架以及配置相应的运行参数。实验三Android触控监听器的使用一、实验目的1.掌握Android项目中界面显示的基本方法;2.掌握OnTouchListener监听器的设计与使用3.掌握Android手机硬件API的调用方法。二、主要仪器设备及套数计算机三、实验内容在Android平台下设计实现滑动的方块应用1.使用屏幕触控,图拽方块移动。2.暂不考虑横屏切换程序代码控制文件:packagecom.ex06_03;importandroid.app.Activity;importandroid.os.Bundle;importandroid.util.Log;importandroid.view.MotionEvent;importandroid.view.View;importandroid.view.View.OnTouchListener;publicclassMainActivityextendsActivity{ intx1=150,y1=50;TestViewtestView;@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);testView=newTestView(this);testView.setOnTouchListener(newmOnTouch());testView.getXY(x1,y1);setContentView(testView);}privateclassmOnTouchimplementsOnTouchListener{ publicbooleanonTouch(Viewv,MotionEventevent) { if(event.getAction()==MotionEvent.ACTION_MOVE) {//在屏幕上滑动(拖动) x1=(int)event.getX(); y1=(int)event.getY();testView.getXY(x1,y1);setContentView(testView); } if(event.getAction()==MotionEvent.ACTION_DOWN) {//点击 x1=(int)event.getX(); y1=(int)event.getY(); Log.i("x=",String.valueOf(x1));Log.i("y=",String.valueOf(y1));testView.getXY(x1,y1);setContentView(testView); } returntrue; }}packagecom.ex06_03;importandroid.content.Context;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Paint;importandroid.view.View;publicclassTestViewextendsView{intx,y; publicTestView(Contextcontext) { super(context); } voidgetXY(int_x,int_y) { x=_x; y=_y; } /*下面编写绘制小球的代码,参见教材例6-3*/ protectedvoidonDraw(Canvascanvas){ super.onDraw(canvas);/*设置背景为青色*/canvas.drawColor(Color.CYAN);Paintpaint=newPaint();/*去锯齿*/paint.setAntiAlias(true);/*设置paint的颜色*/paint.setColor(Color.BLACK);/*画一个实心圆*/canvas.drawRect(x,y,x+30,y+30,paint);paint.setColor(Color.GREEN);/*canvas.drawRect(x-6,y-6,3,3,paint);*/}界面布局:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"/></LinearLayout>实验结果实验小结简单触摸屏事件指在触摸屏上按下、抬起、滑动的事件,在Android系统中,通过OnTouchListener监听接口来处理屏幕事件当在View的范围内进行按下、抬起、滑动等动作时都会触发该事件。在本次试验中我学会了简单应用Android触控监听器来操作屏幕,虽然在实验中遇到了一些困难,但还是受益良多。实验四网络访问与服务一、实验目的掌握Android网络访问方法。二、主要仪器设备及套数计算机三、实验内容1.了解手机WEB网站访问编程,通过HttpResponse类,读入网络数据2.通过网络进行数据访问3.了解数据库使用四、程序代码publicclassslide8_3extendsActivity{PublicStingmyhttpget(Stringurl)throwsException{Stringout=null;Try{HttpClientclient=newDefaultHttpClient();HttpGetrequest=newHttpGet(url);HttpResponserequest=client.execute(request);out=EntityUtils.toString(response.getEntity());}catch(IOExceptione){e.printStackTrace();}returnout;}PublicStringmyhttppost(Stringurl,Stringname,Stringvalue)ThrowEeception{Stringout=null;try{HttpClientclient=newDefaultHttpClient();HttpPostrequest=newHttpPost(url);List<NameValuePair>postParameters=newArrayList<NameValuePair>();postParameters.add(newBasicNameValuePair(name,value));UrlEncodedFormEntity=newEncodedFormEntity=newUrlEncodedFormEntity(postParameters);request.setEntity(formEntity);HttpResponseresponse=client.execute(request);out=EntityUtils.toString(response.getEntity());}catch(IOExceptione){e.printStackTrace();}returnout;@OverridepublicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }FinalTextViewtextview=(TextView)findviewbyid(R.id.TextView01);FinalEditVieweditview=(EditView)findviewbyid(R.id.EditText1);finalEditTextname=(EditText)findviewbyid(R.id.EditText2);finalEditTextvalue=(EditText)findviewbyid(R.id.EditText3);Buttonbtn=(Button)this.findviewbyid(R.id.Button1);btn.setOnClickListener(newButton.OnClickListener(){Publicvoidonclick(Viewv){Try{textView.setText(myhttpget(editText.getText().toString()+”?”+name.getText().toString()+”=”+value.getText().toString()));}catch(Exceptione){e.printStackTrace();}}});Buttonbtn2=(Button)this.findviewbyid(R.id.Button2);Btn2.setOnClickListener(newButton.OnClickListener(){Publicvoidonclick(Viewv){Try{textView.setText(myhttppost(editText.getText().toString(),name.getText().toString(),value.getText().toString()));}catch(Exceptione){e.printStackTrace();}}});}}五、实验结果Get:Post:六、实验小结在这次试验中,我基本掌握了Android访问网络的基本方法,了解了手机WEB网站访问编程,通过HttpResponse类,读入网络数据,再通过网络进行数据访问,最后还基本学会了数据库使用。实验五Android平台下手电应用的设计开发一、实验目的1.掌握Android项目中界面显示的基本方法;2.掌握OnTouchListener监听器的设计与使用3.了解Android手机硬件API的调用方法。二、主要仪器设备及套数计算机三、实验内容1.使用屏幕触控2.调用相机的闪光点硬件,开启手电功能3.暂不考虑横屏切换四、程序代码packagecn.lee.handlight;importandroid.app.Activity;importandroid.hardware.Camera;importandroid.hardware.Camera.Parameters;importandroid.os.Bundle;importandroid.os.Process;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.view.WindowManager;importandroid.widget.ToggleButton;publicclassHandLightActivityextendsActivityimplementsOnClickListener{ privateToggleButtontoggleButton; privateCameracamera=Camera.open(); /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); toggleButton=(ToggleButton)this.findViewById(R.id.tog

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论