Commit 4912f2ed51d5c06a47ea46cd09e0c2bebcad02ab
1 parent
7b881e316b
Exists in
master
Gson
Showing
8 changed files
with
58 additions
and
49 deletions
Show diff stats
PersonalCenter/.idea/misc.xml
... | ... | @@ -27,46 +27,6 @@ |
27 | 27 | </value> |
28 | 28 | </option> |
29 | 29 | </component> |
30 | - <component name="ProjectInspectionProfilesVisibleTreeState"> | |
31 | - <entry key="Project Default"> | |
32 | - <profile-state> | |
33 | - <expanded-state> | |
34 | - <State> | |
35 | - <id /> | |
36 | - </State> | |
37 | - <State> | |
38 | - <id>Class structureJava</id> | |
39 | - </State> | |
40 | - <State> | |
41 | - <id>Code maturity issuesJava</id> | |
42 | - </State> | |
43 | - <State> | |
44 | - <id>Java</id> | |
45 | - </State> | |
46 | - <State> | |
47 | - <id>Java language level migration aidsJava</id> | |
48 | - </State> | |
49 | - <State> | |
50 | - <id>Javadoc issuesJava</id> | |
51 | - </State> | |
52 | - <State> | |
53 | - <id>Performance issuesJava</id> | |
54 | - </State> | |
55 | - <State> | |
56 | - <id>TestNGJava</id> | |
57 | - </State> | |
58 | - <State> | |
59 | - <id>Threading issuesJava</id> | |
60 | - </State> | |
61 | - </expanded-state> | |
62 | - <selected-state> | |
63 | - <State> | |
64 | - <id>Android</id> | |
65 | - </State> | |
66 | - </selected-state> | |
67 | - </profile-state> | |
68 | - </entry> | |
69 | - </component> | |
70 | 30 | <component name="ProjectLevelVcsManager" settingsEditedManually="false"> |
71 | 31 | <OptionsSetting value="true" id="Add" /> |
72 | 32 | <OptionsSetting value="true" id="Remove" /> | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/RegisterInfoActivity.java
... | ... | @@ -78,7 +78,7 @@ public class RegisterInfoActivity extends AppCompatActivity implements View.OnCl |
78 | 78 | } |
79 | 79 | //选择地区 |
80 | 80 | private void choiseregion() { |
81 | - HttpManager.getInstance().countyinfo(RegisterInfoActivity.this,210300); | |
81 | + HttpManager.getInstance().provices(RegisterInfoActivity.this); | |
82 | 82 | ProvinceListDialog.getInstance().show(getSupportFragmentManager(), "ProvinceListDialog"); |
83 | 83 | } |
84 | 84 | //选择年级 | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/ProvinceListDialog.java
... | ... | @@ -13,6 +13,7 @@ import android.widget.ListView; |
13 | 13 | import android.widget.Toast; |
14 | 14 | |
15 | 15 | import com.hjx.personalcenter.R; |
16 | +import com.hjx.personalcenter.db.SaveParam; | |
16 | 17 | import com.mylhyl.circledialog.BaseCircleDialog; |
17 | 18 | import com.mylhyl.circledialog.res.values.CircleDimen; |
18 | 19 | |
... | ... | @@ -44,9 +45,9 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
44 | 45 | public void onActivityCreated(Bundle savedInstanceState) { |
45 | 46 | super.onActivityCreated(savedInstanceState); |
46 | 47 | listView = (ListView) getView().findViewById(R.id.listadapter); |
47 | - | |
48 | - for (int i =0 ; i<50;i++){ | |
49 | - data.add("sss"+1); | |
48 | + String ranging = SaveParam.getInstance().getCustomizeParam(getActivity(),SaveParam.PROVINCES); | |
49 | + for (int i =0 ; i<ranging.split(",").length;i++){ | |
50 | + data.add(i,ranging.replaceAll(",","省")); | |
50 | 51 | |
51 | 52 | } |
52 | 53 | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/db/SaveParam.java
PersonalCenter/app/src/main/java/com/hjx/personalcenter/gson/GsonTool.java
... | ... | @@ -0,0 +1,40 @@ |
1 | +package com.hjx.personalcenter.gson; | |
2 | + | |
3 | +import java.util.ArrayList; | |
4 | +import java.util.List; | |
5 | + | |
6 | +import com.google.gson.Gson; | |
7 | +import com.google.gson.reflect.TypeToken; | |
8 | + | |
9 | +public class GsonTool { | |
10 | + | |
11 | + public GsonTool() { | |
12 | + // TODO Auto-generated constructor stub | |
13 | + } | |
14 | + | |
15 | + //使用Gson进行解析Person | |
16 | + public static <T> T getPerson(String jsonString, Class<T> cls) { | |
17 | + T t = null; | |
18 | + try { | |
19 | + Gson gson = new Gson(); | |
20 | + t = gson.fromJson(jsonString, cls); | |
21 | + } catch (Exception e) { | |
22 | + // TODO: handle exception | |
23 | + } | |
24 | + return t; | |
25 | + } | |
26 | + | |
27 | + | |
28 | + // 使用Gson进行解析 List<Person> | |
29 | + public static <T> List<T> getPersons(String jsonString, Class<T> cls) { | |
30 | + List<T> list = new ArrayList<T>(); | |
31 | + try { | |
32 | + Gson gson = new Gson(); | |
33 | + list = gson.fromJson(jsonString, new TypeToken<List<T>>() { | |
34 | + }.getType()); | |
35 | + } catch (Exception e) { | |
36 | + } | |
37 | + return list; | |
38 | + } | |
39 | + | |
40 | +} | |
0 | 41 | \ No newline at end of file | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/http/HttpManager.java
... | ... | @@ -12,6 +12,7 @@ import android.widget.Toast; |
12 | 12 | import com.google.gson.Gson; |
13 | 13 | import com.hjx.personalcenter.activity.LoginAndRegisterActivity; |
14 | 14 | import com.hjx.personalcenter.db.SaveParam; |
15 | +import com.hjx.personalcenter.gson.GsonTool; | |
15 | 16 | import com.hjx.personalcenter.model.CityInfo; |
16 | 17 | import com.hjx.personalcenter.model.CountyInfo; |
17 | 18 | import com.hjx.personalcenter.model.ProvinceInfo; |
... | ... | @@ -300,16 +301,20 @@ public class HttpManager { |
300 | 301 | @Override |
301 | 302 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { |
302 | 303 | Log.e("test", "省" + new String(arg2)); |
303 | - Gson gson = new Gson(); | |
304 | - ProvinceInfo provinceInfo = gson.fromJson(new String(arg2),ProvinceInfo.class); | |
304 | + ProvinceInfo provinceInfo = GsonTool.getPerson(new String(arg2), ProvinceInfo.class);//解析json数据 | |
305 | + Log.e("test", "状态码" +provinceInfo.getStatus()); | |
306 | + StringBuffer sb = new StringBuffer(); | |
305 | 307 | for (int i =0 ; i<provinceInfo.getProvinces().size();i++){ |
306 | 308 | Log.e("test", "省" +provinceInfo.getProvinces().get(i) |
307 | 309 | .getParentId()); |
308 | 310 | Log.e("test", "省" +provinceInfo.getProvinces().get(i) |
309 | 311 | .getRegionId()); |
310 | - Log.e("test", "省" +provinceInfo.getProvinces().get(i).getRegionName()+""); | |
312 | + Log.e("test", "省" +provinceInfo.getProvinces().get(i).getRegionName()); | |
313 | + sb.append(provinceInfo.getProvinces().get(i).getRegionName()+","); | |
311 | 314 | |
312 | 315 | } |
316 | + Log.e("test", "省" +sb.toString()); | |
317 | + SaveParam.getInstance().saveCustomizeParam(mContext,SaveParam.PROVINCES, "" + sb.toString()); | |
313 | 318 | |
314 | 319 | |
315 | 320 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/model/ProvinceInfo.java
PersonalCenter/build.gradle
... | ... | @@ -5,7 +5,7 @@ buildscript { |
5 | 5 | jcenter() |
6 | 6 | } |
7 | 7 | dependencies { |
8 | - classpath 'com.android.tools.build:gradle:2.2.2' | |
8 | + classpath 'com.android.tools.build:gradle:2.2.3' | |
9 | 9 | |
10 | 10 | // NOTE: Do not place your application dependencies here; they belong |
11 | 11 | // in the individual module build.gradle files | ... | ... |