Android beginners (3) progressbar and listview

Source: Internet
Author: User

I. Summary

Today we are going to learn about two slightly more complex widgets.

Progressbar is often used for file loading, processing, and downloading.

Listview is used to display content in the form of a list.

Final effect:


Ii. Three elements of listview:

1. listveiw is used to display the view of the list.

2. the adapter is used to map data to the mediation on the listview.

3. The specific string, image, or basic component of the data to be mapped.

Based on the list of adapter types, the list is divided into three types: arrayadapter, simpleadapter, and simplecursoradapter

Arrayadapter is the simplest and can only display one line of words. Simpleadapter has the best scalability and Can Customize various effects. Simplecursoradapter can be considered as a simple combination of simpleadapter on the database. It can display the database content in the form of a list.

Progressbar is relatively simple, with circular and long bars.


Iii. Code:

Here, the progressbar and listview are placed in an acivity.

Mainactivy. Java

Package COM. example. activity_02; import Java. util. arraylist; import Java. util. hashmap; import Java. util. map; import android. OS. bundle; import android. app. activity; import android. app. alertdialog; import android. view. menuitem; import android. view. view; import android. view. view. onclicklistener; import android. widget. adapterview; import android. widget. adapterview. onitemclicklistener; import android. widget. button; Import android. widget. listview; import android. widget. progressbar; import android. widget. simpleadapter; import android. widget. toast; public class mainactivity extends activity {private progressbar myprogressbar1 = NULL; private progressbar myprogressbar2 = NULL; private button mybutton = NULL; private listview mylistview = NULL; private simpleadapter myadapter = NULL; private int I = 0; @ overridepublic void oncreate (Bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); myprogressbar1 = (progressbar) findviewbyid (R. id. myprogressbar1); myprogressbar2 = (progressbar) findviewbyid (R. id. myprogressbar2); mybutton = (button) findviewbyid (R. id. mybutton); mybutton. setonclicklistener (New buttonlistener (); mylistview = (listview) findviewbyid (R. id. mylistview); // generates a dynamic array and reprints the arraylist data. <Hashmap <string, string> mylist = new arraylist 

<!--my_listitem.xml--><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/myListItem"    android:layout_width="fill_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:paddingBottom="3dip"    android:paddingLeft="10dip" >    <TextView        android:id="@+id/ItemTitle"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:textSize="30dip" >    </TextView>    <TextView        android:id="@+id/ItemText"        android:layout_width="fill_parent"        android:layout_height="wrap_content" >    </TextView></LinearLayout>


<!--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>



Vi. References

Android Developers: http://developer.android.com/training/basics/firstapp/running-app.html Google official tutorials, very recommended.

Rayyi's blog: http://www.cnblogs.com/rayee/tag/Android/ is only four, but as an entry tutorial is still very good.

Android development Tutorial: tutorials circulating on the Internet. The disadvantage is that they are a little old.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.