Android Network Framework-Volley practices using Volley to create custom ListView, android-volley

Source: Internet
Author: User

Android Network Framework-Volley practices using Volley to create custom ListView, android-volley

This article is translated from Android Custom ListView with Image and Text using Volley in the Ravi Tamada blog.

Final Effect

This ListView displays some video information, each row is the information of a video, each row contains a picture of a movie, the name, score, type, year, and other information of the movie.

1. json data

We parse json and get the data. The json data includes a json array. Each json array contains a json object, the json object contains the url, title, year, rating, type, and other information of the movie image.

JSON Url: http://api.androidhive.info/json/movies.json

2. Download the Volley Library (volley. jar)

If you use the Volley framework for the first time, I suggest you go to my previous article and read the Working Principle Analysis of the Android network framework Volley (I. Then download a volley. jar file from Baidu. Add to project lib folder

3. Layout Analysis

I chose RelativeLayout to implement this layout. We use the NetworkImageView provided by volley.

Now let's create an Android project.

4. Create a new project

1.Open eclipse and click File> New> Android Application Project. After filling in the basic information, we name the package info. androidhive. customlistviewvolley.

2.Add volley. jar to the lib folder of the project.

3.We first build the package, and we divide it into four packages:Adapter,App,ModelAndUtil.The project structure is as follows:

Info. androidhive. customlistviewvolley. adater
Info. androidhive. customlistviewvolley. app
Info. androidhive. customlistviewvolley. model
Info. androidhive. customlistviewvolley. util

4.Open res/values/colors. xml. If you do not have colors. xml, you can create one by yourself. Then add the following code:

5.Open res/values/dimens. xml. Add the following code:

6.Before writing the jsva code, complete the UI section, create a drawable folder under res, and create three xml files in res/drawable: List_row_bg.xml and list_row_bg_hover.xml, List_row_selector.xml.
List_row_bg.xml-The listview style when the button is not clicked List_row_bg_hover.xml-Listview style after clicking List_row_selector.xml-Switch the slector files of the two styles. 7.Open Activity_main.xmlAdd listview

8.Create a layout file for each item List_row.xml We have completed the UI part, followed by the java code section 9.Create under util package LruBitmapCache. javaThis class is used to cache images. This class has been analyzed in previous articles. See the Android network framework-Volley (2) RequestQueue source code analysis and the establishment of a RequestQueue 10.Create under app package AppController. javaThis class is used to create a singleton RequestQueue and initialize some core volley objects. 11.Now we want AndroidManifest. xmlTo register this AppController and add the network access permission. 12.Create a Movie object class under the model package. The parsed json data is saved to this object class. 13.Create CustomListAdapter. javaThe adapter loads the item layout and displays the data on the listview. 14.Open MainActivity. java. Add the following code. We use JsonArrayRequest to send a request. We have already discussed how to send a json request using the get and post methods in the Android network framework Volley (4. We store the resolved Movie object in an ArrayList and call the yydatasetchanged () method to notify listview to update our data.

Zookeeper

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.