8001511072夏先国实验六第七章Android基本控件下.docx

上传人:b****6 文档编号:6948559 上传时间:2023-01-13 格式:DOCX 页数:16 大小:185.53KB
下载 相关 举报
8001511072夏先国实验六第七章Android基本控件下.docx_第1页
第1页 / 共16页
8001511072夏先国实验六第七章Android基本控件下.docx_第2页
第2页 / 共16页
8001511072夏先国实验六第七章Android基本控件下.docx_第3页
第3页 / 共16页
8001511072夏先国实验六第七章Android基本控件下.docx_第4页
第4页 / 共16页
8001511072夏先国实验六第七章Android基本控件下.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

8001511072夏先国实验六第七章Android基本控件下.docx

《8001511072夏先国实验六第七章Android基本控件下.docx》由会员分享,可在线阅读,更多相关《8001511072夏先国实验六第七章Android基本控件下.docx(16页珍藏版)》请在冰豆网上搜索。

8001511072夏先国实验六第七章Android基本控件下.docx

8001511072夏先国实验六第七章Android基本控件下

南昌大学实验报告

学生姓名:

夏先国学号8001511072专业班级:

软件技术112班

实验类型:

□验证□综合

设计□创新实验日期:

2013-05-08实验成绩:

一、实验项目名称

Android中的基本控件(下)

二、实验目的

经一步掌握安卓中的控件

三、实验要求

完成以下实验

1.滚动视图ScrollView

2.列表显示ListView

3.对话框Dialog

4.随笔提示文本Dialog

5.滚动条SeekBar

6.评分组件RatingBar

四、主要仪器设备及耗材

PC机一台,JDK,eclispce,sdk

五、实验步骤及处理结果

1.滚动视图ScrollView

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android:

id="@+id/myscroll"

xmlns:

android="

android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

xmlns:

android="

android:

orientation="vertical"

android:

id="@+id/mylinear"

android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

 

Activity

packageorg.lxh.demo;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.view.ViewGroup;

importandroid.widget.Button;

importandroid.widget.LinearLayout;

publicclassMyScrollViewDemoextendsActivity{

privateStringdata[]={"北京魔乐科技","","讲师:

李兴华",

"中国高校讲师联盟","","咨询邮箱:

mldnqa@",

"客户服务:

mldnkf@","客户电话:

(010)51283346","魔乐社区:

",

"程序员招聘网:

};//准备出若干个信息而这些信息以后将通过程序加入到内嵌的线性布局文件之中

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

super.setContentView(R.layout.main);//调用默认的布局管理器

LinearLayoutlayout=(LinearLayout)super.findViewById(R.id.mylinear);//取得组件

LinearLayout.LayoutParamsparam=newLinearLayout.LayoutParams(

ViewGroup.LayoutParams.FILL_PARENT,

ViewGroup.LayoutParams.WRAP_CONTENT);//定义布局参数

for(intx=0;x

Buttonbut=newButton(this);

but.setText(this.data[x]);//设置显示文字

layout.addView(but,param);//增加组件

}

}

}

效果截图:

2.列表显示ListView

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

orientation="vertical"

android:

layout_width="fill_parent"

android:

layout_height="fill_parent"

>

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

text="@string/hello"

/>

Activity

packageorg.lxh.demo;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.widget.ArrayAdapter;

importandroid.widget.ListView;

publicclassMyListViewDemoextendsActivity{

privateStringdata[]={"北京魔乐科技","","讲师:

李兴华",

"中国高校讲师联盟","","咨询邮箱:

mldnqa@",

"客户服务:

mldnkf@","客户电话:

(010)51283346","魔乐社区:

",

"程序员招聘网:

};//准备出若干个信息而这些信息以后将通过程序加入到内嵌的线性布局文件之中

privateListViewlistView=null;//定义ListView组件

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

this.listView=newListView(this);//实例化组件

this.listView.setAdapter(newArrayAdapter(this,

android.R.layout.simple_expandable_list_item_1,this.data));//为ListView组件设置内容

super.setContentView(this.listView);//显示组件

}

}

效果截图:

3.对话框Dialog

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

orientation="vertical"android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

android:

id="@+id/mybut"

android:

text="查找网络"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"/>

Login.xml

xmlversion="1.0"encoding="utf-8"?

>

xmlns:

android="

android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

android:

text="用户名:

"

android:

layout_marginLeft="20dip"

android:

textSize="8pt"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"/>

android:

width="60pt"

android:

layout_height="wrap_content"/>

android:

text="密码:

"

android:

layout_marginLeft="20dip"

android:

textSize="8pt"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"/>

android:

password="true"

android:

width="60pt"

android:

layout_height="wrap_content"/>

Activity

效果截图:

4.随笔提示文本AutoCompleteTextView

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

orientation="vertical"android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

android:

id="@+id/myauto"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"/>

Activity

packageorg.lxh.demo;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.widget.ArrayAdapter;

importandroid.widget.AutoCompleteTextView;

publicclassMyAutoCompleteTextViewDemoextendsActivity{

privatestaticfinalStringDATA[]=newString[]{"mldn","mldnjava",

"mldn魔乐科技","mldn李兴华","mldnjob"};

privateAutoCompleteTextViewmyauto=null;

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

super.setContentView(R.layout.main);

ArrayAdapteradapter=newArrayAdapter(this,

android.R.layout.simple_dropdown_item_1line,DATA);//数据集

this.myauto=(AutoCompleteTextView)super.findViewById(R.id.myauto);//取得组件

this.myauto.setAdapter(adapter);//设置内容

}

}

效果截图:

5.拖动条SeekBar

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

orientation="vertical"android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

android:

id="@+id/pic"

android:

src="@drawable/pic_0"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"/>

android:

id="@+id/seekbar"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"/>

Activity

packageorg.lxh.demo;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.text.method.ScrollingMovementMethod;

importandroid.widget.ImageView;

importandroid.widget.SeekBar;

importandroid.widget.TextView;

publicclassMySeekBarDemoextendsActivity{

privateSeekBarseekbar=null;

privateImageViewpic=null;

privateintpicData[]=newint[]{R.drawable.pic_0,R.drawable.pic_1,

R.drawable.pic_2,R.drawable.pic_3,R.drawable.pic_4,

R.drawable.pic_5,R.drawable.pic_6,R.drawable.pic_7,

R.drawable.pic_8,R.drawable.pic_9};

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

super.setContentView(R.layout.main);

this.seekbar=(SeekBar)super.findViewById(R.id.seekbar);//取得组件

this.pic=(ImageView)super.findViewById(R.id.pic);//取得组件

this.seekbar.setMax(9);//0~9的范围

this.seekbar

.setOnSeekBarChangeListener(newOnSeekBarChangeListenerImpl());

}

privateclassOnSeekBarChangeListenerImplimplements

SeekBar.OnSeekBarChangeListener{

@Override

publicvoidonStartTrackingTouch(SeekBarseekBar){

}

@Override

publicvoidonProgressChanged(SeekBarseekBar,intprogress,

booleanfromUser){

MySeekBarDemo.this.pic

.setImageResource(MySeekBarDemo.this.picData[seekBar

.getProgress()]);//设置显示图片

}

@Override

publicvoidonStopTrackingTouch(SeekBarseekBar){

}

}

}

效果截图:

6.评分组件RatingBar

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

orientation="vertical"android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

android:

id="@+id/ratingbar"

android:

numStars="6"

android:

stepSize="1"

android:

isIndicator="false"

style="@style/myRatingBar"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"/>

android:

id="@+id/text"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"/>

Activity

packageorg.lxh.demo;

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.widget.RatingBar;

importandroid.widget.RatingBar.OnRatingBarChangeListener;

importandroid.widget.TextView;

publicclassMyRatingBarDemoextendsActivity{

privateRatingBarratingBar=null;

privateTextViewtext=null;

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

super.setContentView(R.layout.main);

this.ratingBar=(RatingBar)super.findViewById(R.id.ratingbar);

this.text=(TextView)super.findViewById(R.id.text);

this.ratingBar.setOnRatingBarChangeListener(newOnRatingBarChangeListenerImpl());

}

privateclassOnRatingBarChangeListenerImplimplementsOnRatingBarChangeListener{

@Override

publicvoidonRatingChanged(RatingBarratingBar,floatrating,

booleanfromUser){

intnum=(int)rating;

Stringresult=null;//保存文字信息

switch(num){

case5:

result="非常满意";

break;

case4:

result="满意";

break;

case3:

result="还可以";

break;

case2:

result="不满意";

break;

case1:

result="非常不满意";

break;

}

MyRatingBarDemo.this.text.setText(result);

}

}

}

效果截图:

六、参考资料

《Android开发实战经典》李兴华主编清华大学出版社

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1