Android Development--Asynchronous loading

Source: Internet
Author: User

Because mobile-side software development thinking mode or the development of the architecture is in fact platform and programming language, for Android and iOS, they are mobile front-end app development display data and user interaction Data Terminal, mobile architecture of several large modules: UI display, local data sustainable storage, Network data requests, performance optimizations, and so on, both Android and iOS developers have to consider the modules of these architectures. So, the people familiar with the development of iOS, and then to learn about the development of Android and Android development model, you will find a lot of technology and ideas Android and iOS are the same, but probably not the same, because programming languages such as OC and Java slightly different, coding habits and details are not the same, the others are the same.

I began to have a little interest in Android, started on the superficial study of Android, on the one hand will be compared with iOS and Android, if you will iOS, then learn Android, read my blog may be a great help to you.

(But for Android development of the language base Java, and the use of Android studio, I will not elaborate, as a feeling of independent ability of the programmer, these foundations should not be your bar, not to mention I on Android Studio has been using Google and Baidu to learn about setting and shortcut keys.

In Android, the two most common ways to load asynchronously are:

1. Multithreading \ Thread Pool

2, Asynctask

Of course, the Asynctask bottom layer is based on the thread pool implementation. So the above two methods are similar to each other.

First, as with the idea of loading data with UITableView in iOS, let's first create a custom cell and a cell layout:

New Item_layout.xml File:

Source:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Wrap_content"5 android:padding= "4DP"6 android:orientation= "Horizontal"7     >8     <ImageView9         Android:id= "@+id/iv_icon"Ten Android:layout_width= "64DP" One Android:layout_height= "64DP" A android:src= "@mipmap/ic_launcher"/> -  -  the     <LinearLayout -         Android:layout_width= "Match_parent" - Android:layout_height= "Match_parent" - android:padding= "4DP" + android:gravity= "Center" - android:orientation= "vertical"> +  A         <TextView at             Android:id= "@+id/tv_title" - Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" - android:textsize= "15SP" - Android:maxlines= "1" - Android:text= " Title title title"/> in  -  to         <TextView +             Android:id= "@+id/tv_content" - Android:layout_width= "Match_parent" the Android:layout_height= "Wrap_content" * android:textsize= "10SP" $ Android:maxlines= "3"Panax Notoginseng Android:text= " content content content"/> -  the     </LinearLayout> +  A  the </LinearLayout>

In this way, a custom item is created, just like the UITableViewCell created on our iOS xib or storyboard.

Then create a ListView in Activity_main.xml, which is like the UITableView of our iOS.

Source:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:id= "@+id/activity_main"5 Android:layout_width= "Match_parent"6 Android:layout_height= "Match_parent"7 Android:paddingbottom= "@dimen/activity_vertical_margin"8 Android:paddingleft= "@dimen/activity_horizontal_margin"9 Android:paddingright= "@dimen/activity_horizontal_margin"Ten Android:paddingtop= "@dimen/activity_vertical_margin" One Tools:context= "Com.example.heyang.myapplication.MainActivity"> A  -     <ListView -         Android:id= "@+id/lv_main" the Android:layout_width= "Match_parent" - Android:layout_height= "Match_parent" -         /> -  +  - </Relativelayout>

Second, because each item or analogy iOS each cell needs a picture address, title title, content three data, so we need a model object to one by one mapping corresponds to the item, in Android or Java is called to create a Bean object, In fact, it can be interpreted as the model object of iOS.

Source:

1  Packagecom.example.heyang.myapplication;2 3 /**4 * Created by Heyang on 16/10/5.5  */6 7  Public classNewsbean {8     //contains three attributes: 1, Title 2, content 3, image URL9      PublicString Newsiconurl;Ten      PublicString Newstitle; One      PublicString newscontent; A}

Android Development--Asynchronous loading

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.