This article is translated from the Android custom ListView in Ravi Tamada blog with Image and Text using volley
Finally 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
By parsing the JSON and then getting the data, the JSON data contains the JSON array. In each JSON array is a JSON object that contains the picture URL address, title, year, rating, type, and so on for the movie
JSON Url:http://api.androidhive.info/json/movies.json
2. Download Volley library (Volley.jar)
Assuming you're 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. Added to the project's Lib directory
3. Layout analysis
I chose relativelayout to implement this layout, the images we use volley provide Networkimageview
Now we're going to build 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 directory
3. Let's build the package first. We are divided into 4 packages: adapter, app, model and util.
Today 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.
Assuming there is no colors.xml, we create one ourselves. Then add code such as the following
5.Open Res/values/dimens.xml. Add code such as the following
6.Before writing the JSVA code, let's complete the UI section, create a new drawable directory under Res, and create a new 3 XML file in res/drawable:List_row_bg.xml, List_row_bg_hover.xml、List_row_selector.xml。
List_row_bg.xml-style of ListView without being clickedList_row_bg_hover.xml-The style of the ListView after being clickedList_row_selector.xml-Toggle between two styles of slector files7.Open itActivity_main.xmlJoin ListView
8.Create a layout file for each itemList_row.xmlUI section We're finished, and here's the Java Code section.9.New under the Util packageLrubitmapcache.javaThis class is used to cache images, which we have already analyzed in the previous article. See Android Network Framework-volley (ii) Requestqueue source code Analysis and build a requestqueue.Create a new item under the app packageAppcontroller.javaThis class is used to create a singleton requestqueue, and to initialize some volley core objectsOne by one .Now we are going toAndroidmanifest.xmlRegister this AppController, and join the network permissions.Now a movie entity class is created under the model package, and the parsed JSON data is saved to this entity class.Create a new one under the adapter packageCustomlistadapter.javaAdapter will load the item layout in. and show the data to the ListView..Open our Mainactivity.java.
Adding code like the following, 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 requests have been talked about. 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 your own custom ListView