This article mainly introduces in detail the implementation of Android news browsing client based on PHP background, which has certain reference value. Interested friends can refer to
1. Use HBuilder for PHP environment Configuration and testing whether MySQL statements can be queried have been explained in detail before.
2. The PHP background here implements the query function of mysql and returns a client in JSON data format.
Create a mysql_connect.php file here in PHP to realize the database connection and Set character set format.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Then create a new getNewsJSON.php file to convert the query results into JSON string format. Only the json_encode method is needed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
The focus is on the design and development of the Android side
1. Design interface
Since it is necessary to set the same format in each Item of the ListView, the ListView Adapter is used here The form
Add a ListView control in the main interface LinearLayout
2. The Mainactivity program is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
A tool class HttpUtils and a custom NewsAdapter are required here to implement The view display of item.
HttpUtils code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
NewsAdapter code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
news_item is used to set the display format of each item
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
Note: This item needs to display a single image, so the Bitmap class is used. Since network transmission is used, the concept of thread needs to be used! !
The key is to understand the relationship between handler message and loop.
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to implement simple encryption technology in PHP
PHP simple guestbook function implementation code
PHP Sharing Examples of Implementing the Avatar Changing Function for Multiple Users
The above is the detailed content of Implementing Android news browsing client based on PHP background. For more information, please follow other related articles on the PHP Chinese website!