首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android入门(三)ProgressBar和ListView

2012-09-14 
Android入门(3)ProgressBar和ListView一、提要今天要学习的是两个稍微复杂一些的控件。ProgressBar经常用于

Android入门(3)ProgressBar和ListView

一、提要

       今天要学习的是两个稍微复杂一些的控件。

      ProgressBar经常用于文件载入,处理文件,下载等场合。

      ListView用于以列表的形式展示内容。

     最终效果:

Android入门(三)ProgressBar和ListView     


二、ListView三个元素:

1.ListVeiw 用来展示列表的View。

2.适配器 用来把数据映射到ListView上的中介。

3.数据    具体的将被映射的字符串,图片,或者基本组件。

根据列表的适配器类型,列表分为三种,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter

其中以ArrayAdapter最为简单,只能展示一行字。SimpleAdapter有最好的扩充性,可以自定义出各种效果。SimpleCursorAdapter可以认为是SimpleAdapter对数据库的简单结合,可以方面的把数据库的内容以列表的形式展示出来。

ProgressBar比较简单,有圆形和长条形。


三、代码:

这里把ProgressBar和ListView放在一个Acivity里了。

MainActivy.java

<!--activity_main.xml--><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:id="@+id/myTextView"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/tip1"        android:textSize="20dp" />    <ProgressBar        android:id="@+id/myProgressBar1"        style="?android:attr/progressBarStyleHorizontal"        android:layout_width="200dp"        android:layout_height="wrap_content"        android:visibility="gone" />    <ProgressBar        android:id="@+id/myProgressBar2"        style="?android:attr/progressBarStyle"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:visibility="gone" />    <Button        android:id="@+id/myButton"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/tip2" />    <TextView        android:id="@+id/myTextView2"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/tip3"        android:textSize="20dp" />    <ListView        android:id="@+id/myListView"        android:layout_width="wrap_content"        android:layout_height="wrap_content" >    </ListView></LinearLayout>



六、参考资料

Android developers:http://developer.android.com/training/basics/firstapp/running-app.html   google的官方教程,非常推荐。

雷一的博客:http://www.cnblogs.com/rayee/tag/Android/ 素然只有四篇,但作为入门教程还是很不错的。

Android 开发教程:网上流传的教程,缺点是有点老。

热点排行