《夏先国实验六第七章Android基本控件(下).doc》由会员分享,可在线阅读,更多相关《夏先国实验六第七章Android基本控件(下).doc(15页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、 南昌大学实验报告学生姓名: 夏先国 学 号 专业班级:软件技术112班 实验类型:验证综合设计创新实验日期:2013-05-08实验成绩: 一、实验项目名称Android中的基本控件(下)二、实验目的经一步掌握安卓中的控件三、实验要求完成以下实验1.滚动视图ScrollView2.列表显示ListView3.对话框Dialog4.随笔提示文本Dialog5.滚动条SeekBar6.评分组件RatingBar四、主要仪器设备及耗材PC 机一台,JDK,eclispce,sdk五、实验步骤及处理结果1.滚动视图ScrollViewmain.xmlActivitypackage org.lxh.d
2、emo;import android.app.Activity;import android.os.Bundle;import android.view.ViewGroup;import android.widget.Button;import android.widget.LinearLayout;public class MyScrollViewDemo extends Activity private String data = 北京魔乐科技, , 讲师:李兴华,中国高校讲师联盟, , 咨询邮箱:mldnqa,客户服务:mldnkf, 客户电话:(010) , 魔乐社区:,程序员招聘网:
3、 ; / 准备出若干个信息而这些信息以后将通过程序加入到内嵌的线性布局文件之中Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);super.setContentView(R.layout.main); / 调用默认的布局管理器LinearLayout layout = (LinearLayout) super.findViewById(R.id.mylinear); / 取得组件LinearLayout.LayoutParams param = new Linea
4、rLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); / 定义布局参数for (int x = 0; x this.data.length; x+) / 通过循环方式将以上的信息通过Button组件进行封装Button but = new Button(this);but.setText(this.datax); / 设置显示文字layout.addView(but, param); / 增加组件效果截图:2.列表显示ListViewmain.xmlActivi
5、typackage org.lxh.demo;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;public class MyListViewDemo extends Activity private String data = 北京魔乐科技, , 讲师:李兴华,中国高校讲师联盟, , 咨询邮箱:mldnqa,客户服务:mldnkf, 客户电话:(010) , 魔乐社区:,程序员招聘网: ; / 准备出若干个
6、信息而这些信息以后将通过程序加入到内嵌的线性布局文件之中private ListView listView = null; / 定义ListView组件Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);this.listView = new ListView(this); / 实例化组件this.listView.setAdapter(new ArrayAdapter(this,android.R.layout.simple_expandable_list_ite
7、m_1, this.data); / 为ListView组件设置内容 super.setContentView(this.listView); / 显示组件效果截图:3.对话框Dialogmain.xmlLogin.xmlActivity效果截图:4.随笔提示文本AutoCompleteTextViewmain.xmlActivitypackage org.lxh.demo;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.A
8、utoCompleteTextView;public class MyAutoCompleteTextViewDemo extends Activity private static final String DATA = new String mldn, mldn java,mldn魔乐科技, mldn李兴华, mldn job ;private AutoCompleteTextView myauto = null;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState
9、);super.setContentView(R.layout.main);ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, DATA); / 数据集this.myauto = (AutoCompleteTextView) super.findViewById(R.id.myauto); / 取得组件this.myauto.setAdapter(adapter); / 设置内容效果截图:5.拖动条SeekBarmain.xml Activitypackage org
10、.lxh.demo;import android.app.Activity;import android.os.Bundle;import android.text.method.ScrollingMovementMethod;import android.widget.ImageView;import android.widget.SeekBar;import android.widget.TextView;public class MySeekBarDemo extends Activity private SeekBar seekbar = null;private ImageView
11、pic = null;private int picData = new int 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 ;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstan
12、ceState);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(new OnSeekBarChangeListenerImpl();private class OnSeekBarCh
13、angeListenerImpl implementsSeekBar.OnSeekBarChangeListener Overridepublic void onStartTrackingTouch(SeekBar seekBar) Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) MySeekBarDemo.this.pic.setImageResource(MySeekBarDemo.this.picDataseekBar.getProgress();/ 设置显示图片O
14、verridepublic void onStopTrackingTouch(SeekBar seekBar) 效果截图:6.评分组件RatingBarmain.xmlActivitypackage org.lxh.demo;import android.app.Activity;import android.os.Bundle;import android.widget.RatingBar;import android.widget.RatingBar.OnRatingBarChangeListener;import android.widget.TextView;public class
15、MyRatingBarDemo extends Activity private RatingBar ratingBar = null;private TextView text = null;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);super.setContentView(R.layout.main);this.ratingBar = (RatingBar) super.findViewById(R.id.ratingbar);this.text =
16、(TextView) super.findViewById(R.id.text);this.ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListenerImpl() ;private class OnRatingBarChangeListenerImpl implements OnRatingBarChangeListener Overridepublic void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser) int num = (int) rating;String result = null ;/ 保存文字信息switch(num) case 5:result = 非常满意 ;break ;case 4:result = 满意 ;break ;case 3:result = 还可以 ;break ;case 2:result = 不满意 ;break ;case 1:result = 非常不满意 ;break ;MyRatingBarDemo.this.text.setText(result) ;效果截图:六、参考资料Android开发实战经典 李兴华主编 清华大学出版社