Android Network framework-volley practice using volley to create custom ListView

Source: Internet
Author: User

This article is translated from the Android custom ListView in Ravi Tamada blog with Image and Text using volley

Final effect

This listview presents some film and television information, each line is a piece of information about a movie, each row has a picture of the film, the name of the movie, the rating, type, year and other information.

1.json data

We parse the JSON and get the data, the JSON data includes the JSON array, each JSON array is a JSON object, the JSON object includes the picture URL address of the movie, title, year, rating, type and other information

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

2. Download Volley library (Volley.jar)

If you are using the volley framework for the first time, I suggest you go to my previous article to see the Android Network Framework-volley (a) Working principle analysis. Then go to Baidu to download a volley.jar. Add to Project's Lib folder

3. Layout analysis

I chose relativelayout to implement this layout, the images we use volley provide Networkimageview

Now let's create a new 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 name Info.androidhive.customlistviewvolley.

2. add Volley.jar to the project's Lib folder

3. We build the package first, we are divided into 4 packages: adapter, app, model and util. now our 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 there is no colors.xml, we will create one ourselves. Then add the following code

5.Open Res/values/dimens.xml. Add the following code

6.Before writing the JSVA code, let's complete the UI section, create a new drawable folder under Res, and create a new 3 XML file in res/drawable: List_row_bg.xml, List_row_bg_hover.xmlList_row_selector.xml
List_row_bg.xml-style of ListView without being clicked List_row_bg_hover.xml-The style of the ListView after being clicked List_row_selector.xml-Toggle between two styles of slector files 7.Open it Activity_main.xmlAdd ListView

8.Create a layout file for each item List_row.xml UI section We're done, next to the Java Code section 9.New under the Util package Lrubitmapcache.javaThis class is used to cache images, which we have already analyzed in the previous article. See Android Network Framework-volley (ii) Requestqueue source analysis and building a requestqueue .Create a new item under the app package Appcontroller.javaThis class is used to create a singleton requestqueue, and to initialize some volley core objects One by one .Now we're going to Androidmanifest.xmlRegister this appcontroller and add network permissions .Now create a movie entity class under the model package, and the parsed JSON data will be saved to this entity class .Create a new one under the adapter package Customlistadapter.javaAdapter will load the item layout and display the data to the ListView .Open our Mainactivity.java. Add the following code, we use Jsonarrayrequest to send requests, we send JSON requests in the Android Network framework-volley (iv) using the GET and post methods to send JSON request has been told. We store the parsed movie object in a ArrayList and call the Notifydatasetchanged () method to notify the ListView to update our data.



Android Network framework-volley practice using volley to create custom ListView

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.