Commit 78458fa9f2ddd16d9e43aaddaf2d927e5ab7f9fc
1 parent
0ff2ad496e
Exists in
master
数据模型的使用
Showing
11 changed files
with
304 additions
and
100 deletions
Show diff stats
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/RegisterInfoActivity.java
| ... | ... | @@ -12,9 +12,12 @@ import android.widget.EditText; |
| 12 | 12 | import android.widget.TextView; |
| 13 | 13 | |
| 14 | 14 | import com.hjx.personalcenter.R; |
| 15 | +import com.hjx.personalcenter.customdialog.CitysListDialog; | |
| 16 | +import com.hjx.personalcenter.customdialog.CountryDialog; | |
| 15 | 17 | import com.hjx.personalcenter.customdialog.GradeListDialog; |
| 16 | 18 | import com.hjx.personalcenter.customdialog.ProvinceListDialog; |
| 17 | 19 | import com.hjx.personalcenter.customdialog.SchoolListDialog; |
| 20 | +import com.hjx.personalcenter.db.SaveParam; | |
| 18 | 21 | import com.hjx.personalcenter.http.HttpManager; |
| 19 | 22 | import com.hjx.personalcenter.interfaces.DialogCallBack; |
| 20 | 23 | import com.hjx.personalcenter.util.AlertUtils; |
| ... | ... | @@ -74,12 +77,12 @@ public class RegisterInfoActivity extends AppCompatActivity implements View.OnCl |
| 74 | 77 | choisegrade(); |
| 75 | 78 | break; |
| 76 | 79 | case R.id.et_school: |
| 77 | - if (TextUtils.isEmpty(register2) || TextUtils.isEmpty(register3)){ | |
| 78 | - AlertUtils.showToast(RegisterInfoActivity.this, "请选择年级和地址"); | |
| 79 | - return; | |
| 80 | - }else { | |
| 80 | +// if (TextUtils.isEmpty(register2) || TextUtils.isEmpty(register3)){ | |
| 81 | +// AlertUtils.showToast(RegisterInfoActivity.this, "请选择年级和地址"); | |
| 82 | +// return; | |
| 83 | + // }else { | |
| 81 | 84 | choiseschool(); |
| 82 | - } | |
| 85 | + // } | |
| 83 | 86 | |
| 84 | 87 | break; |
| 85 | 88 | case R.id.btn_ok: |
| ... | ... | @@ -101,10 +104,8 @@ public class RegisterInfoActivity extends AppCompatActivity implements View.OnCl |
| 101 | 104 | |
| 102 | 105 | //选择地区 |
| 103 | 106 | private void choiseregion() { |
| 104 | - HttpManager.getInstance().provices(RegisterInfoActivity.this); | |
| 107 | + | |
| 105 | 108 | ProvinceListDialog.getInstance(this).show(getSupportFragmentManager(), "ProvinceListDialog"); |
| 106 | -// HttpManager.getInstance().cityinfo(RegisterInfoActivity.this,111); | |
| 107 | -// CitysListDialog.getInstance(this).show(getSupportFragmentManager(), "CitysListDialog"); | |
| 108 | 109 | |
| 109 | 110 | } |
| 110 | 111 | //选择年级 |
| ... | ... | @@ -115,18 +116,36 @@ public class RegisterInfoActivity extends AppCompatActivity implements View.OnCl |
| 115 | 116 | } |
| 116 | 117 | //选择学校 |
| 117 | 118 | private void choiseschool() { |
| 118 | - HttpManager.getInstance().getschool(RegisterInfoActivity.this,130102,14); | |
| 119 | 119 | SchoolListDialog.getInstance().show(getSupportFragmentManager(), "SchoolListDialog"); |
| 120 | 120 | |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | @Override |
| 125 | - public void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id) { | |
| 125 | + public void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id,int type) { | |
| 126 | + | |
| 127 | + if (type==1){ | |
| 128 | + View gradeView = parent.getChildAt(position); | |
| 129 | + TextView gradeTv = (TextView)gradeView.findViewById(R.id.list_items); | |
| 130 | + SaveParam.getInstance().saveLoginParam(this,"sheng",gradeTv.getText().toString()); | |
| 131 | + CitysListDialog.getInstance(this).show(getSupportFragmentManager(), "CitysListDialog"); | |
| 132 | + } | |
| 133 | + | |
| 134 | + if (type==2){ | |
| 135 | + View gradeView = parent.getChildAt(position); | |
| 136 | + TextView gradeTv = (TextView)gradeView.findViewById(R.id.list_items); | |
| 137 | + SaveParam.getInstance().saveLoginParam(this,"shi",gradeTv.getText().toString()); | |
| 138 | + CountryDialog.getInstance(this).show(getSupportFragmentManager(), "CountryDialog"); | |
| 139 | + } | |
| 140 | + | |
| 141 | + if (type==3){ | |
| 142 | + View gradeView = parent.getChildAt(position); | |
| 143 | + TextView gradeTv = (TextView)gradeView.findViewById(R.id.list_items); | |
| 144 | + String provice = SaveParam.getInstance().getLoginParam(this,"sheng"); | |
| 145 | + String citys = SaveParam.getInstance().getLoginParam(this,"shi"); | |
| 146 | + et_region.setText(provice+citys+gradeTv.getText().toString()); | |
| 147 | + } | |
| 126 | 148 | |
| 127 | - View gradeView = parent.getChildAt(position); | |
| 128 | - TextView gradeTv = (TextView)gradeView.findViewById(R.id.list_items); | |
| 129 | - et_region.setText(gradeTv.getText().toString()); | |
| 130 | 149 | |
| 131 | 150 | |
| 132 | 151 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/adapter/CitysAdapter.java
| ... | ... | @@ -53,7 +53,7 @@ public class CitysAdapter extends BaseAdapter { |
| 53 | 53 | holder = (ProvincesAdapter.ViewHolder) convertView.getTag(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - holder.nameText.setText(objects.get(position).getRegionName()); | |
| 56 | + holder.nameText.setText(objects.get(position).getRegionName()+"市"); | |
| 57 | 57 | |
| 58 | 58 | return convertView; |
| 59 | 59 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/adapter/CountryAdapter.java
| ... | ... | @@ -0,0 +1,66 @@ |
| 1 | +package com.hjx.personalcenter.adapter; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.view.View; | |
| 5 | +import android.view.ViewGroup; | |
| 6 | +import android.widget.BaseAdapter; | |
| 7 | +import android.widget.TextView; | |
| 8 | + | |
| 9 | +import com.hjx.personalcenter.R; | |
| 10 | +import com.hjx.personalcenter.model.CityInfo; | |
| 11 | +import com.hjx.personalcenter.model.CountyInfo; | |
| 12 | + | |
| 13 | +import java.util.ArrayList; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Created by wei on 2017/8/21. | |
| 17 | + */ | |
| 18 | + | |
| 19 | +public class CountryAdapter extends BaseAdapter{ | |
| 20 | + ArrayList<CountyInfo.CountiesBean> objects; | |
| 21 | + private Context context; | |
| 22 | + | |
| 23 | + public CountryAdapter(ArrayList<CountyInfo.CountiesBean> objects, Context context) { | |
| 24 | + this.objects = objects; | |
| 25 | + this.context = context; | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public int getCount() { | |
| 30 | + return objects.size(); | |
| 31 | + } | |
| 32 | + | |
| 33 | + @Override | |
| 34 | + public Object getItem(int position) { | |
| 35 | + return position; | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public long getItemId(int position) { | |
| 40 | + return position; | |
| 41 | + } | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public View getView(final int position, View convertView, ViewGroup parent) { | |
| 45 | + | |
| 46 | + ProvincesAdapter.ViewHolder holder = null; | |
| 47 | + | |
| 48 | + if (convertView == null) { | |
| 49 | + convertView = View.inflate(context, R.layout.custom_adilog_list_item, null); | |
| 50 | + holder = new ProvincesAdapter.ViewHolder(); | |
| 51 | + holder.nameText = (TextView) convertView.findViewById(R.id.list_items); | |
| 52 | + convertView.setTag(holder); | |
| 53 | + } else { | |
| 54 | + holder = (ProvincesAdapter.ViewHolder) convertView.getTag(); | |
| 55 | + } | |
| 56 | + | |
| 57 | + holder.nameText.setText(objects.get(position).getRegionName()+"区"); | |
| 58 | + | |
| 59 | + return convertView; | |
| 60 | + } | |
| 61 | + | |
| 62 | + | |
| 63 | + static class ViewHolder { | |
| 64 | + TextView nameText; | |
| 65 | + } | |
| 66 | +} | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/adapter/ProvincesAdapter.java
| ... | ... | @@ -53,7 +53,7 @@ public class ProvincesAdapter extends BaseAdapter { |
| 53 | 53 | holder = (ProvincesAdapter.ViewHolder) convertView.getTag(); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - holder.nameText.setText(objects.get(position).getRegionName()); | |
| 56 | + holder.nameText.setText(objects.get(position).getRegionName()+"省"); | |
| 57 | 57 | |
| 58 | 58 | return convertView; |
| 59 | 59 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/CitysListDialog.java
| ... | ... | @@ -3,6 +3,8 @@ package com.hjx.personalcenter.customdialog; |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | import android.graphics.Color; |
| 5 | 5 | import android.os.Bundle; |
| 6 | +import android.os.Handler; | |
| 7 | +import android.os.Message; | |
| 6 | 8 | import android.view.Gravity; |
| 7 | 9 | import android.view.LayoutInflater; |
| 8 | 10 | import android.view.View; |
| ... | ... | @@ -13,12 +15,16 @@ import android.widget.ListView; |
| 13 | 15 | import com.hjx.personalcenter.R; |
| 14 | 16 | import com.hjx.personalcenter.adapter.CitysAdapter; |
| 15 | 17 | import com.hjx.personalcenter.db.SaveParam; |
| 18 | +import com.hjx.personalcenter.http.HttpCode; | |
| 19 | +import com.hjx.personalcenter.http.HttpManager; | |
| 16 | 20 | import com.hjx.personalcenter.interfaces.DialogCallBack; |
| 17 | 21 | import com.hjx.personalcenter.model.CityInfo; |
| 22 | +import com.hjx.personalcenter.model.ProvinceInfo; | |
| 18 | 23 | import com.mylhyl.circledialog.BaseCircleDialog; |
| 19 | 24 | import com.mylhyl.circledialog.res.values.CircleDimen; |
| 20 | 25 | |
| 21 | 26 | import java.util.ArrayList; |
| 27 | +import java.util.List; | |
| 22 | 28 | |
| 23 | 29 | /** |
| 24 | 30 | * 自定义市级列表对话框 |
| ... | ... | @@ -43,6 +49,19 @@ public class CitysListDialog extends BaseCircleDialog implements AdapterView.OnI |
| 43 | 49 | dialogFragment.setBackgroundColor(Color.WHITE); |
| 44 | 50 | return dialogFragment; |
| 45 | 51 | } |
| 52 | + Handler handler = new Handler(){ | |
| 53 | + @Override | |
| 54 | + public void handleMessage(Message msg) { | |
| 55 | + super.handleMessage(msg); | |
| 56 | + switch (msg.what){ | |
| 57 | + case HttpCode.CITYS: | |
| 58 | + data.clear(); | |
| 59 | + data.addAll( (List<CityInfo.CitiesBean>)msg.obj); | |
| 60 | + listadapter.notifyDataSetChanged(); | |
| 61 | + break; | |
| 62 | + } | |
| 63 | + } | |
| 64 | + }; | |
| 46 | 65 | |
| 47 | 66 | @Override |
| 48 | 67 | public View createView(Context context, LayoutInflater inflater, ViewGroup container) { |
| ... | ... | @@ -53,31 +72,24 @@ public class CitysListDialog extends BaseCircleDialog implements AdapterView.OnI |
| 53 | 72 | public void onActivityCreated(Bundle savedInstanceState) { |
| 54 | 73 | super.onActivityCreated(savedInstanceState); |
| 55 | 74 | listView = (ListView) getView().findViewById(R.id.listadapter); |
| 56 | - String provinces = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.CITYS); | |
| 57 | -// if (provinces != null) { | |
| 58 | -// | |
| 59 | -// for (int i = 0; i < provinces.split(",").length; i++) { | |
| 60 | -// String[] itmt = provinces.split(","); | |
| 61 | -// data.add(itmt[i] + "区"); | |
| 62 | -// //data.add(i,provinces.replaceAll(",","省")); | |
| 63 | -// | |
| 64 | -// } | |
| 65 | -// } else { | |
| 66 | -// HttpManager.getInstance().provices(getActivity()); | |
| 67 | -// } | |
| 68 | - | |
| 75 | + String citys = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.PROVINCES); | |
| 69 | 76 | listadapter = new CitysAdapter(data,getActivity()); |
| 70 | 77 | listView.setAdapter(listadapter); |
| 71 | 78 | listView.setOnItemClickListener(this); |
| 79 | + try { | |
| 80 | + int a = Integer.parseInt(citys); | |
| 81 | + HttpManager.getInstance().cityinfo(getActivity(),a,handler); | |
| 82 | + } catch (NumberFormatException e) { | |
| 83 | + e.printStackTrace(); | |
| 84 | + } | |
| 85 | + | |
| 72 | 86 | |
| 73 | 87 | } |
| 74 | 88 | |
| 75 | 89 | @Override |
| 76 | 90 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 77 | - mCallBack.provinceOnItemClick(parent,view,position,id); | |
| 78 | - | |
| 79 | - | |
| 80 | - | |
| 91 | + SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.CITYS, ""+data.get(position).getRegionId()); | |
| 92 | + mCallBack.provinceOnItemClick(parent,view,position,id,2); | |
| 81 | 93 | dismiss(); |
| 82 | 94 | |
| 83 | 95 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/CountryDialog.java
| ... | ... | @@ -0,0 +1,96 @@ |
| 1 | +package com.hjx.personalcenter.customdialog; | |
| 2 | + | |
| 3 | +import android.content.Context; | |
| 4 | +import android.graphics.Color; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.os.Handler; | |
| 7 | +import android.os.Message; | |
| 8 | +import android.view.Gravity; | |
| 9 | +import android.view.LayoutInflater; | |
| 10 | +import android.view.View; | |
| 11 | +import android.view.ViewGroup; | |
| 12 | +import android.widget.AdapterView; | |
| 13 | +import android.widget.ListView; | |
| 14 | + | |
| 15 | +import com.hjx.personalcenter.R; | |
| 16 | +import com.hjx.personalcenter.adapter.CitysAdapter; | |
| 17 | +import com.hjx.personalcenter.adapter.CountryAdapter; | |
| 18 | +import com.hjx.personalcenter.db.SaveParam; | |
| 19 | +import com.hjx.personalcenter.http.HttpCode; | |
| 20 | +import com.hjx.personalcenter.http.HttpManager; | |
| 21 | +import com.hjx.personalcenter.interfaces.DialogCallBack; | |
| 22 | +import com.hjx.personalcenter.model.CityInfo; | |
| 23 | +import com.hjx.personalcenter.model.CountyInfo; | |
| 24 | +import com.mylhyl.circledialog.BaseCircleDialog; | |
| 25 | +import com.mylhyl.circledialog.res.values.CircleDimen; | |
| 26 | + | |
| 27 | +import java.util.ArrayList; | |
| 28 | +import java.util.List; | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * Created by wei on 2017/8/21. | |
| 32 | + */ | |
| 33 | + | |
| 34 | +public class CountryDialog extends BaseCircleDialog implements AdapterView.OnItemClickListener { | |
| 35 | + private CountryAdapter listadapter; | |
| 36 | + private ListView listView; | |
| 37 | + private DialogCallBack.CallBack mCallBack; | |
| 38 | + private ArrayList<CountyInfo.CountiesBean> data = new ArrayList<>(); | |
| 39 | + public CountryDialog(DialogCallBack.CallBack callBack) { | |
| 40 | + this.mCallBack = callBack; | |
| 41 | + } | |
| 42 | + public static CountryDialog getInstance(DialogCallBack.CallBack callBack) { | |
| 43 | + CountryDialog dialogFragment = new CountryDialog(callBack); | |
| 44 | + dialogFragment.setCanceledBack(true); | |
| 45 | + dialogFragment.setCanceledOnTouchOutside(true); | |
| 46 | + dialogFragment.setRadius(CircleDimen.RADIUS); | |
| 47 | + dialogFragment.setWidth(0.5f); | |
| 48 | + dialogFragment.setGravity(Gravity.CENTER); | |
| 49 | + dialogFragment.setBackgroundColor(Color.WHITE); | |
| 50 | + return dialogFragment; | |
| 51 | + } | |
| 52 | + Handler handler = new Handler(){ | |
| 53 | + @Override | |
| 54 | + public void handleMessage(Message msg) { | |
| 55 | + super.handleMessage(msg); | |
| 56 | + switch (msg.what){ | |
| 57 | + case HttpCode.COUNTRY: | |
| 58 | + data.clear(); | |
| 59 | + data.addAll( (List<CountyInfo.CountiesBean>)msg.obj); | |
| 60 | + listadapter.notifyDataSetChanged(); | |
| 61 | + break; | |
| 62 | + } | |
| 63 | + } | |
| 64 | + }; | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public View createView(Context context, LayoutInflater inflater, ViewGroup container) { | |
| 68 | + return inflater.inflate(R.layout.custom_adilog_provicelist, container, false); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public void onActivityCreated(Bundle savedInstanceState) { | |
| 73 | + super.onActivityCreated(savedInstanceState); | |
| 74 | + listView = (ListView) getView().findViewById(R.id.listadapter); | |
| 75 | + String citys = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.CITYS); | |
| 76 | + listadapter = new CountryAdapter(data,getActivity()); | |
| 77 | + listView.setAdapter(listadapter); | |
| 78 | + listView.setOnItemClickListener(this); | |
| 79 | + try { | |
| 80 | + int a = Integer.parseInt(citys); | |
| 81 | + HttpManager.getInstance().countyinfo(getActivity(),a,handler); | |
| 82 | + } catch (NumberFormatException e) { | |
| 83 | + e.printStackTrace(); | |
| 84 | + } | |
| 85 | + | |
| 86 | + | |
| 87 | + } | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
| 91 | + SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.CITYS, ""+data.get(position).getRegionId()); | |
| 92 | + mCallBack.provinceOnItemClick(parent,view,position,id,3); | |
| 93 | + dismiss(); | |
| 94 | + | |
| 95 | + } | |
| 96 | +} | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/ProvinceListDialog.java
| ... | ... | @@ -3,6 +3,8 @@ package com.hjx.personalcenter.customdialog; |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | import android.graphics.Color; |
| 5 | 5 | import android.os.Bundle; |
| 6 | +import android.os.Handler; | |
| 7 | +import android.os.Message; | |
| 6 | 8 | import android.view.Gravity; |
| 7 | 9 | import android.view.LayoutInflater; |
| 8 | 10 | import android.view.View; |
| ... | ... | @@ -11,8 +13,10 @@ import android.widget.AdapterView; |
| 11 | 13 | import android.widget.ListView; |
| 12 | 14 | |
| 13 | 15 | import com.hjx.personalcenter.R; |
| 16 | +import com.hjx.personalcenter.activity.RegisterInfoActivity; | |
| 14 | 17 | import com.hjx.personalcenter.adapter.ProvincesAdapter; |
| 15 | 18 | import com.hjx.personalcenter.db.SaveParam; |
| 19 | +import com.hjx.personalcenter.http.HttpCode; | |
| 16 | 20 | import com.hjx.personalcenter.http.HttpManager; |
| 17 | 21 | import com.hjx.personalcenter.interfaces.DialogCallBack; |
| 18 | 22 | import com.hjx.personalcenter.model.ProvinceInfo; |
| ... | ... | @@ -20,6 +24,7 @@ import com.mylhyl.circledialog.BaseCircleDialog; |
| 20 | 24 | import com.mylhyl.circledialog.res.values.CircleDimen; |
| 21 | 25 | |
| 22 | 26 | import java.util.ArrayList; |
| 27 | +import java.util.List; | |
| 23 | 28 | |
| 24 | 29 | /** |
| 25 | 30 | * 自定义年级列表对话框 |
| ... | ... | @@ -33,6 +38,19 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
| 33 | 38 | |
| 34 | 39 | private DialogCallBack.CallBack mCallBack; |
| 35 | 40 | |
| 41 | + Handler handler = new Handler(){ | |
| 42 | + @Override | |
| 43 | + public void handleMessage(Message msg) { | |
| 44 | + super.handleMessage(msg); | |
| 45 | + switch (msg.what){ | |
| 46 | + case HttpCode.PROVICES: | |
| 47 | + data.clear(); | |
| 48 | + data.addAll( (List<ProvinceInfo.ProvincesBean>)msg.obj); | |
| 49 | + listadapter.notifyDataSetChanged(); | |
| 50 | + break; | |
| 51 | + } | |
| 52 | + } | |
| 53 | + }; | |
| 36 | 54 | public ProvinceListDialog(DialogCallBack.CallBack callBack) { |
| 37 | 55 | this.mCallBack = callBack; |
| 38 | 56 | } |
| ... | ... | @@ -57,28 +75,18 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
| 57 | 75 | public void onActivityCreated(Bundle savedInstanceState) { |
| 58 | 76 | super.onActivityCreated(savedInstanceState); |
| 59 | 77 | listView = (ListView) getView().findViewById(R.id.listadapter); |
| 60 | - String provinces = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.PROVINCES); | |
| 61 | - if (provinces != null) { | |
| 62 | - | |
| 63 | - for (int i = 0; i < provinces.split(",").length; i++) { | |
| 64 | - ProvinceInfo.ProvincesBean provincesBean = new ProvinceInfo.ProvincesBean(); | |
| 65 | - provincesBean.setRegionName(provinces.split(",")[i] + "省"); | |
| 66 | - data.add(provincesBean); | |
| 67 | - } | |
| 68 | - } else { | |
| 69 | - HttpManager.getInstance().provices(getActivity()); | |
| 70 | - } | |
| 71 | - | |
| 72 | 78 | listadapter = new ProvincesAdapter(data,getActivity()); |
| 73 | 79 | listView.setAdapter(listadapter); |
| 74 | 80 | listView.setOnItemClickListener(this); |
| 81 | + HttpManager.getInstance().provices(getActivity(),handler); | |
| 75 | 82 | |
| 76 | 83 | } |
| 77 | 84 | |
| 78 | 85 | @Override |
| 79 | 86 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 80 | 87 | //Toast.makeText(getActivity(), "你点击了第" + position + "个", Toast.LENGTH_LONG).show(); |
| 81 | - mCallBack.provinceOnItemClick(parent,view,position,id); | |
| 88 | + SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.PROVINCES, ""+data.get(position).getRegionId()); | |
| 89 | + mCallBack.provinceOnItemClick(parent,view,position,id,1); | |
| 82 | 90 | dismiss(); |
| 83 | 91 | |
| 84 | 92 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/SchoolListDialog.java
| ... | ... | @@ -3,6 +3,8 @@ package com.hjx.personalcenter.customdialog; |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | import android.graphics.Color; |
| 5 | 5 | import android.os.Bundle; |
| 6 | +import android.os.Handler; | |
| 7 | +import android.os.Message; | |
| 6 | 8 | import android.text.Editable; |
| 7 | 9 | import android.text.TextWatcher; |
| 8 | 10 | import android.view.Gravity; |
| ... | ... | @@ -14,15 +16,19 @@ import android.widget.EditText; |
| 14 | 16 | import android.widget.ListView; |
| 15 | 17 | |
| 16 | 18 | import com.hjx.personalcenter.R; |
| 19 | +import com.hjx.personalcenter.activity.RegisterInfoActivity; | |
| 17 | 20 | import com.hjx.personalcenter.adapter.SchoolAdapter; |
| 18 | 21 | import com.hjx.personalcenter.db.SaveParam; |
| 22 | +import com.hjx.personalcenter.http.HttpCode; | |
| 19 | 23 | import com.hjx.personalcenter.http.HttpManager; |
| 20 | 24 | import com.hjx.personalcenter.interfaces.DialogCallBack; |
| 25 | +import com.hjx.personalcenter.model.CountyInfo; | |
| 21 | 26 | import com.hjx.personalcenter.model.SchoolInfo; |
| 22 | 27 | import com.mylhyl.circledialog.BaseCircleDialog; |
| 23 | 28 | import com.mylhyl.circledialog.res.values.CircleDimen; |
| 24 | 29 | |
| 25 | 30 | import java.util.ArrayList; |
| 31 | +import java.util.List; | |
| 26 | 32 | |
| 27 | 33 | /** |
| 28 | 34 | * Created by h on 2017/8/21. |
| ... | ... | @@ -51,7 +57,19 @@ public class SchoolListDialog extends BaseCircleDialog implements AdapterView.On |
| 51 | 57 | dialogFragment.setBackgroundColor(Color.WHITE); |
| 52 | 58 | return dialogFragment; |
| 53 | 59 | } |
| 54 | - | |
| 60 | + Handler handler = new Handler(){ | |
| 61 | + @Override | |
| 62 | + public void handleMessage(Message msg) { | |
| 63 | + super.handleMessage(msg); | |
| 64 | + switch (msg.what){ | |
| 65 | + case HttpCode.SCHOOL: | |
| 66 | + data.clear(); | |
| 67 | + data.addAll( (List<SchoolInfo.DataBean>)msg.obj); | |
| 68 | + listadapter.notifyDataSetChanged(); | |
| 69 | + break; | |
| 70 | + } | |
| 71 | + } | |
| 72 | + }; | |
| 55 | 73 | @Override |
| 56 | 74 | public View createView(Context context, LayoutInflater inflater, ViewGroup container) { |
| 57 | 75 | |
| ... | ... | @@ -67,21 +85,17 @@ public class SchoolListDialog extends BaseCircleDialog implements AdapterView.On |
| 67 | 85 | super.onActivityCreated(savedInstanceState); |
| 68 | 86 | school_list = (ListView) getView().findViewById(R.id.listschooladapter); |
| 69 | 87 | school_sech = (EditText) getView().findViewById(R.id.et_school_sech); |
| 70 | - String gradens = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.SCHOOL); | |
| 71 | - if (gradens != null) { | |
| 72 | - | |
| 73 | - for (int i = 0; i < gradens.split(",").length; i++) { | |
| 74 | - SchoolInfo.DataBean dataBean = new SchoolInfo.DataBean(); | |
| 75 | - dataBean.setSchoolName(gradens.split(",")[i]); | |
| 76 | - data.add(dataBean); | |
| 77 | - } | |
| 78 | - } else { | |
| 79 | - HttpManager.getInstance().getschool(getActivity(),130102,14); | |
| 80 | - } | |
| 88 | + String citys = SaveParam.getInstance().getLoginParam(getActivity(), SaveParam.CITYS); | |
| 81 | 89 | listadapter = new SchoolAdapter(data, getActivity()); |
| 82 | 90 | school_list.setAdapter(listadapter); |
| 83 | 91 | school_list.setOnItemClickListener(this); |
| 84 | 92 | school_sech.setOnClickListener(this); |
| 93 | + try { | |
| 94 | + int a = Integer.parseInt(citys); | |
| 95 | + HttpManager.getInstance().getschool(getActivity(),a,14,handler); | |
| 96 | + } catch (NumberFormatException e) { | |
| 97 | + e.printStackTrace(); | |
| 98 | + } | |
| 85 | 99 | intiEditView(); |
| 86 | 100 | |
| 87 | 101 | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/http/HttpCode.java
| ... | ... | @@ -25,12 +25,12 @@ public class HttpCode { |
| 25 | 25 | public static final int PASSWORD_FAIL = 10; |
| 26 | 26 | //s省 |
| 27 | 27 | public static final int PROVICES = 11; |
| 28 | - //姓名 | |
| 29 | - public static final int CHANGENAME_SUCESS = 12; | |
| 30 | - //获取个人信息 | |
| 31 | - public static final int STUDENTINFO_SUCESS = 13; | |
| 32 | - //意见反馈 | |
| 33 | - public static final int FEEDBACL_SUCESS = 14; | |
| 28 | + //市 | |
| 29 | + public static final int CITYS = 12; | |
| 30 | + //区 | |
| 31 | + public static final int COUNTRY = 13; | |
| 32 | + //学校 | |
| 33 | + public static final int SCHOOL = 14; | |
| 34 | 34 | //私人订制查询 |
| 35 | 35 | public static final int PRIVATEDZ = 15; |
| 36 | 36 | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/http/HttpManager.java
| ... | ... | @@ -41,6 +41,7 @@ import org.json.JSONException; |
| 41 | 41 | import org.json.JSONObject; |
| 42 | 42 | |
| 43 | 43 | import java.io.UnsupportedEncodingException; |
| 44 | +import java.util.List; | |
| 44 | 45 | |
| 45 | 46 | public class HttpManager { |
| 46 | 47 | private static HttpManager instance; |
| ... | ... | @@ -717,21 +718,18 @@ public class HttpManager { |
| 717 | 718 | }); |
| 718 | 719 | } |
| 719 | 720 | ///获取学校 |
| 720 | - public void getschool(final Context mContext,int regionId,int gradeId) { | |
| 721 | + public void getschool(final Context mContext, int regionId, int gradeId, final Handler handler) { | |
| 721 | 722 | HttpClient.getInstance().addHeader("Accept", "application/json"); |
| 722 | 723 | HttpClient.getInstance().get(HttpUrl.schoolUrl+ "?regionId=" + regionId+ "&gradeId=" + gradeId, new AsyncHttpResponseHandler() { |
| 723 | 724 | @Override |
| 724 | 725 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { |
| 725 | 726 | Log.e("test", "学校" + new String(arg2)); |
| 726 | 727 | SchoolInfo schoolInfo = GsonTool.getPerson(new String(arg2), SchoolInfo.class);//解析json数据 |
| 727 | - StringBuffer sb = new StringBuffer(); | |
| 728 | - for (int i = 0; i < schoolInfo.getData().size(); i++) { | |
| 729 | - sb.append(schoolInfo.getData().get(i).getSchoolName() + ","); | |
| 730 | - | |
| 731 | - } | |
| 732 | - Log.e("test", "学校" + sb.toString()); | |
| 733 | - SaveParam.getInstance().saveLoginParam(mContext, SaveParam.SCHOOL, "" + sb.toString()); | |
| 734 | - | |
| 728 | + List<SchoolInfo.DataBean> schoolInfoBeanList = schoolInfo.getData(); | |
| 729 | + Message message = Message.obtain(); | |
| 730 | + message.what = HttpCode.SCHOOL; | |
| 731 | + message.obj = schoolInfoBeanList; | |
| 732 | + handler.sendMessage(message); | |
| 735 | 733 | |
| 736 | 734 | } |
| 737 | 735 | |
| ... | ... | @@ -767,7 +765,7 @@ public class HttpManager { |
| 767 | 765 | |
| 768 | 766 | |
| 769 | 767 | ///省级接口 |
| 770 | - public void provices(final Context mContext) { | |
| 768 | + public void provices(final Context mContext, final Handler handler) { | |
| 771 | 769 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
| 772 | 770 | HttpClient.getInstance().get(HttpUrl.provinceUrl, new AsyncHttpResponseHandler() { |
| 773 | 771 | @Override |
| ... | ... | @@ -775,14 +773,11 @@ public class HttpManager { |
| 775 | 773 | Log.e("test", "省" + new String(arg2)); |
| 776 | 774 | ProvinceInfo provinceInfo = GsonTool.getPerson(new String(arg2), ProvinceInfo.class);//解析json数据 |
| 777 | 775 | Log.e("test", "状态码" + provinceInfo.getStatus()); |
| 778 | - StringBuffer sb = new StringBuffer(); | |
| 779 | - for (int i = 0; i < provinceInfo.getProvinces().size(); i++) { | |
| 780 | - sb.append(provinceInfo.getProvinces().get(i).getRegionName() + ","); | |
| 781 | - | |
| 782 | - } | |
| 783 | - Log.e("test", "省" + sb.toString()); | |
| 784 | - SaveParam.getInstance().saveLoginParam(mContext, SaveParam.PROVINCES, "" + sb.toString()); | |
| 785 | - | |
| 776 | + List<ProvinceInfo.ProvincesBean> provincesBeanList = provinceInfo.getProvinces(); | |
| 777 | + Message message = Message.obtain(); | |
| 778 | + message.what = HttpCode.PROVICES; | |
| 779 | + message.obj = provincesBeanList; | |
| 780 | + handler.sendMessage(message); | |
| 786 | 781 | |
| 787 | 782 | } |
| 788 | 783 | |
| ... | ... | @@ -814,7 +809,7 @@ public class HttpManager { |
| 814 | 809 | } |
| 815 | 810 | |
| 816 | 811 | //市级接口 |
| 817 | - public void cityinfo(final Context mContext, int regionId) { | |
| 812 | + public void cityinfo(final Context mContext, int regionId , final Handler handler) { | |
| 818 | 813 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
| 819 | 814 | HttpClient.getInstance().get(HttpUrl.cityUrl + "?regionId=" + regionId, new AsyncHttpResponseHandler() { |
| 820 | 815 | @Override |
| ... | ... | @@ -822,14 +817,11 @@ public class HttpManager { |
| 822 | 817 | Log.e("test", "市" + new String(arg2)); |
| 823 | 818 | Gson gson = new Gson(); |
| 824 | 819 | CityInfo cityInfo = gson.fromJson(new String(arg2), CityInfo.class); |
| 825 | - for (int i = 0; i < cityInfo.getCities().size(); i++) { | |
| 826 | - Log.e("test", "市" + cityInfo.getCities().get(i) | |
| 827 | - .getParentId()); | |
| 828 | - Log.e("test", "市" + cityInfo.getCities().get(i) | |
| 829 | - .getRegionId()); | |
| 830 | - Log.e("test", "市" + cityInfo.getCities().get(i).getRegionName() + ""); | |
| 831 | - | |
| 832 | - } | |
| 820 | + List<CityInfo.CitiesBean> cityInfoBeanList = cityInfo.getCities(); | |
| 821 | + Message message = Message.obtain(); | |
| 822 | + message.what = HttpCode.CITYS; | |
| 823 | + message.obj = cityInfoBeanList; | |
| 824 | + handler.sendMessage(message); | |
| 833 | 825 | |
| 834 | 826 | |
| 835 | 827 | } |
| ... | ... | @@ -862,7 +854,7 @@ public class HttpManager { |
| 862 | 854 | } |
| 863 | 855 | |
| 864 | 856 | //区县级接口 |
| 865 | - public void countyinfo(final Context mContext, int parentId) { | |
| 857 | + public void countyinfo(final Context mContext, int parentId, final Handler handler) { | |
| 866 | 858 | HttpClient.getInstance().addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); |
| 867 | 859 | HttpClient.getInstance().get(HttpUrl.countyUrl + "?regionId=" + parentId, new AsyncHttpResponseHandler() { |
| 868 | 860 | @Override |
| ... | ... | @@ -870,14 +862,11 @@ public class HttpManager { |
| 870 | 862 | Log.e("test", "区" + new String(arg2)); |
| 871 | 863 | Gson gson = new Gson(); |
| 872 | 864 | CountyInfo countyInfo = gson.fromJson(new String(arg2), CountyInfo.class); |
| 873 | - for (int i = 0; i < countyInfo.getCounties().size(); i++) { | |
| 874 | - Log.e("test", "区" + countyInfo.getCounties().get(i) | |
| 875 | - .getParentId()); | |
| 876 | - Log.e("test", "区" + countyInfo.getCounties().get(i) | |
| 877 | - .getRegionId()); | |
| 878 | - Log.e("test", "区" + countyInfo.getCounties().get(i).getRegionName() + ""); | |
| 879 | - | |
| 880 | - } | |
| 865 | + List<CountyInfo.CountiesBean> countyInfoInfoBeanList = countyInfo.getCounties(); | |
| 866 | + Message message = Message.obtain(); | |
| 867 | + message.what = HttpCode.COUNTRY; | |
| 868 | + message.obj = countyInfoInfoBeanList; | |
| 869 | + handler.sendMessage(message); | |
| 881 | 870 | |
| 882 | 871 | |
| 883 | 872 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/interfaces/DialogCallBack.java
| ... | ... | @@ -12,7 +12,7 @@ import android.widget.AdapterView; |
| 12 | 12 | |
| 13 | 13 | public class DialogCallBack { |
| 14 | 14 | public interface CallBack{ |
| 15 | - void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id); | |
| 15 | + void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id,int type); | |
| 16 | 16 | } |
| 17 | 17 | public interface CallBackView{ |
| 18 | 18 | void provinceOnItemClick(Context context, LayoutInflater inflater, ViewGroup container); | ... | ... |