Commit 865951b7d0d0dc283d699f891f3cc89b40490434
1 parent
e93f210b0a
Exists in
master
解决listview滑动时位置会改变的问题
Showing
9 changed files
with
126 additions
and
68 deletions
Show diff stats
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/MainActivity.java
... | ... | @@ -100,14 +100,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
100 | 100 | private void initData() { |
101 | 101 | //加载个人信息 |
102 | 102 | |
103 | - //初始化图片 | |
104 | - file = new File(FileUtil.getCachePath(this), "user-avatar.jpg"); | |
105 | - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | |
106 | - uri = Uri.fromFile(file); | |
107 | - } else { | |
108 | - //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问) | |
109 | - uri = FileProvider.getUriForFile(MyApplication.getContext(), "com.hjx.personalcenter", file); | |
110 | - } | |
103 | +// //初始化图片 | |
104 | +// file = new File(FileUtil.getCachePath(this), "user-avatar.jpg"); | |
105 | +// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { | |
106 | +// uri = Uri.fromFile(file); | |
107 | +// } else { | |
108 | +// //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问) | |
109 | +// uri = FileProvider.getUriForFile(MyApplication.getContext(), "com.hjx.personalcenter", file); | |
110 | +// } | |
111 | 111 | |
112 | 112 | } |
113 | 113 | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/RegisterInfoActivity.java
... | ... | @@ -19,13 +19,21 @@ import com.hjx.personalcenter.customdialog.ProvinceListDialog; |
19 | 19 | import com.hjx.personalcenter.customdialog.SchoolListDialog; |
20 | 20 | import com.hjx.personalcenter.db.SaveParam; |
21 | 21 | import com.hjx.personalcenter.interfaces.DialogCallBack; |
22 | +import com.hjx.personalcenter.model.CityInfo; | |
23 | +import com.hjx.personalcenter.model.CountyInfo; | |
24 | +import com.hjx.personalcenter.model.GradeInfo; | |
25 | +import com.hjx.personalcenter.model.ProvinceInfo; | |
26 | +import com.hjx.personalcenter.model.SchoolInfo; | |
22 | 27 | import com.hjx.personalcenter.util.AlertUtils; |
23 | 28 | |
29 | +import java.util.ArrayList; | |
30 | + | |
24 | 31 | /**填写注册信息 熊巍 |
25 | 32 | * Created by h on 2017/8/9. |
26 | 33 | */ |
27 | 34 | |
28 | -public class RegisterInfoActivity extends AppCompatActivity implements View.OnClickListener,DialogCallBack.CallBack { | |
35 | +public class RegisterInfoActivity extends AppCompatActivity implements View.OnClickListener,DialogCallBack.GradeCallBack,DialogCallBack.ProvincesCallBack | |
36 | + ,DialogCallBack.CitysCallBack,DialogCallBack.CountryCallBack,DialogCallBack.SchoolCallBack{ | |
29 | 37 | private EditText et_username; |
30 | 38 | private TextView et_region,et_grade,et_school; |
31 | 39 | private Button btn_ok; |
... | ... | @@ -103,51 +111,27 @@ public class RegisterInfoActivity extends AppCompatActivity implements View.OnCl |
103 | 111 | |
104 | 112 | //选择地区 |
105 | 113 | private void choiseregion() { |
106 | - ProvinceListDialog.getInstance(this).show(getSupportFragmentManager(), "ProvinceListDialog"); | |
114 | + ProvinceListDialog.getInstance((DialogCallBack.ProvincesCallBack) RegisterInfoActivity.this).show(getSupportFragmentManager(), "ProvinceListDialog"); | |
107 | 115 | |
108 | 116 | } |
109 | 117 | //选择年级 |
110 | 118 | private void choisegrade() { |
111 | - GradeListDialog.getInstance(this).show(getSupportFragmentManager(), "GradeListDialog"); | |
119 | + GradeListDialog.getInstance((DialogCallBack.GradeCallBack) this).show(getSupportFragmentManager(), "GradeListDialog"); | |
112 | 120 | |
113 | 121 | } |
114 | 122 | //选择学校 |
115 | 123 | private void choiseschool() { |
116 | - SchoolListDialog.getInstance(this).show(getSupportFragmentManager(), "SchoolListDialog"); | |
124 | + SchoolListDialog.getInstance((DialogCallBack.SchoolCallBack) this).show(getSupportFragmentManager(), "SchoolListDialog"); | |
117 | 125 | |
118 | 126 | } |
119 | 127 | |
120 | 128 | |
121 | 129 | @Override |
122 | - public void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id,int type) { | |
123 | - View View = parent.getChildAt(position); | |
124 | - TextView Tv = (TextView)View.findViewById(R.id.list_items); | |
125 | - switch (type){ | |
126 | - | |
127 | - case 1: | |
128 | - SaveParam.getInstance().saveLoginParam(this,"sheng",Tv.getText().toString()); | |
129 | - CitysListDialog.getInstance(this).show(getSupportFragmentManager(), "CitysListDialog"); | |
130 | - break; | |
131 | - case 2: | |
132 | - String provice = SaveParam.getInstance().getLoginParam(this,"sheng"); | |
133 | - SaveParam.getInstance().saveLoginParam(this,"shi",Tv.getText().toString()); | |
134 | - CountryDialog.getInstance(this).show(getSupportFragmentManager(), "CountryDialog"); | |
135 | - et_region.setText(""); | |
136 | - et_region.setText(provice+Tv.getText().toString()); | |
137 | - break; | |
138 | - case 3: | |
139 | - String provices = SaveParam.getInstance().getLoginParam(this,"sheng"); | |
140 | - String citys = SaveParam.getInstance().getLoginParam(this,"shi"); | |
141 | - et_region.setText(""); | |
142 | - et_region.setText(provices+citys+Tv.getText().toString()); | |
143 | - break; | |
144 | - case 4: | |
145 | - et_school.setText(Tv.getText().toString()); | |
146 | - break; | |
147 | - case 5: | |
148 | - et_grade.setText(Tv.getText().toString()); | |
149 | - break; | |
150 | - } | |
130 | + public void provinceOnItemClick(ArrayList<ProvinceInfo.ProvincesBean> data, int position, int type) { | |
131 | + String regionName = data.get(position).getRegionName(); | |
132 | + SaveParam.getInstance().saveLoginParam(this,"sheng",regionName); | |
133 | + CitysListDialog.getInstance((DialogCallBack.CitysCallBack) this).show(getSupportFragmentManager(), "CitysListDialog"); | |
134 | + | |
151 | 135 | |
152 | 136 | } |
153 | 137 | @Override |
... | ... | @@ -158,4 +142,39 @@ public class RegisterInfoActivity extends AppCompatActivity implements View.OnCl |
158 | 142 | } |
159 | 143 | return super.onKeyUp(keyCode, event); |
160 | 144 | } |
145 | + | |
146 | + @Override | |
147 | + public void province3OnItemClick(ArrayList<GradeInfo.DataBean.ChildrenBean> data, int position, int type) { | |
148 | + String regionName = data.get(position).getName(); | |
149 | + et_grade.setText(regionName); | |
150 | + | |
151 | + } | |
152 | + | |
153 | + @Override | |
154 | + public void province1OnItemClick(ArrayList<CityInfo.CitiesBean> data, int position, int type) { | |
155 | + String regionName = data.get(position).getRegionName(); | |
156 | + String provice = SaveParam.getInstance().getLoginParam(this,"sheng"); | |
157 | + SaveParam.getInstance().saveLoginParam(this,"shi",regionName); | |
158 | + CountryDialog.getInstance((DialogCallBack.CountryCallBack) this).show(getSupportFragmentManager(), "CountryDialog"); | |
159 | + et_region.setText(""); | |
160 | + et_region.setText(provice+regionName); | |
161 | + | |
162 | + } | |
163 | + | |
164 | + @Override | |
165 | + public void province2OnItemClick(ArrayList<CountyInfo.CountiesBean> data, int position, int type) { | |
166 | + String regionName = data.get(position).getRegionName(); | |
167 | + String provices = SaveParam.getInstance().getLoginParam(this,"sheng"); | |
168 | + String citys = SaveParam.getInstance().getLoginParam(this,"shi"); | |
169 | + et_region.setText(""); | |
170 | + et_region.setText(provices+citys+regionName); | |
171 | + | |
172 | + } | |
173 | + | |
174 | + @Override | |
175 | + public void provinceO4nItemClick(ArrayList<SchoolInfo.DataBean> data, int position, int type) { | |
176 | + String regionName = data.get(position).getSchoolName(); | |
177 | + et_school.setText(regionName); | |
178 | + | |
179 | + } | |
161 | 180 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/CitysListDialog.java
... | ... | @@ -33,12 +33,12 @@ import java.util.List; |
33 | 33 | public class CitysListDialog extends BaseCircleDialog implements AdapterView.OnItemClickListener { |
34 | 34 | private CitysAdapter listadapter; |
35 | 35 | private ListView listView; |
36 | - private DialogCallBack.CallBack mCallBack; | |
36 | + private DialogCallBack.CitysCallBack mCallBack; | |
37 | 37 | private ArrayList<CityInfo.CitiesBean> data = new ArrayList<>(); |
38 | - public CitysListDialog(DialogCallBack.CallBack callBack) { | |
38 | + public CitysListDialog(DialogCallBack.CitysCallBack callBack) { | |
39 | 39 | this.mCallBack = callBack; |
40 | 40 | } |
41 | - public static CitysListDialog getInstance(DialogCallBack.CallBack callBack) { | |
41 | + public static CitysListDialog getInstance(DialogCallBack.CitysCallBack callBack) { | |
42 | 42 | CitysListDialog dialogFragment = new CitysListDialog(callBack); |
43 | 43 | dialogFragment.setCanceledBack(true); |
44 | 44 | dialogFragment.setCanceledOnTouchOutside(true); |
... | ... | @@ -88,7 +88,7 @@ public class CitysListDialog extends BaseCircleDialog implements AdapterView.OnI |
88 | 88 | @Override |
89 | 89 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
90 | 90 | SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.CITYS, ""+data.get(position).getRegionId()); |
91 | - mCallBack.provinceOnItemClick(parent,view,position,id,2); | |
91 | + mCallBack.province1OnItemClick(data,position,2); | |
92 | 92 | dismiss(); |
93 | 93 | |
94 | 94 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/CountryDialog.java
... | ... | @@ -32,12 +32,12 @@ import java.util.List; |
32 | 32 | public class CountryDialog extends BaseCircleDialog implements AdapterView.OnItemClickListener { |
33 | 33 | private CountryAdapter listadapter; |
34 | 34 | private ListView listView; |
35 | - private DialogCallBack.CallBack mCallBack; | |
35 | + private DialogCallBack.CountryCallBack mCallBack; | |
36 | 36 | private ArrayList<CountyInfo.CountiesBean> data = new ArrayList<>(); |
37 | - public CountryDialog(DialogCallBack.CallBack callBack) { | |
37 | + public CountryDialog(DialogCallBack.CountryCallBack callBack) { | |
38 | 38 | this.mCallBack = callBack; |
39 | 39 | } |
40 | - public static CountryDialog getInstance(DialogCallBack.CallBack callBack) { | |
40 | + public static CountryDialog getInstance(DialogCallBack.CountryCallBack callBack) { | |
41 | 41 | CountryDialog dialogFragment = new CountryDialog(callBack); |
42 | 42 | dialogFragment.setCanceledBack(true); |
43 | 43 | dialogFragment.setCanceledOnTouchOutside(true); |
... | ... | @@ -88,7 +88,7 @@ public class CountryDialog extends BaseCircleDialog implements AdapterView.OnIte |
88 | 88 | @Override |
89 | 89 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
90 | 90 | SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.CITYS, ""+data.get(position).getRegionId()); |
91 | - mCallBack.provinceOnItemClick(parent,view,position,id,3); | |
91 | + mCallBack.province2OnItemClick(data,position,3); | |
92 | 92 | dismiss(); |
93 | 93 | |
94 | 94 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/GradeListDialog.java
... | ... | @@ -33,11 +33,11 @@ public class GradeListDialog extends BaseCircleDialog implements AdapterView.OnI |
33 | 33 | private GrandeAdapter listadapter; |
34 | 34 | private ListView listView; |
35 | 35 | ArrayList<GradeInfo.DataBean.ChildrenBean> data = new ArrayList<>(); |
36 | - private DialogCallBack.CallBack mCallBack; | |
37 | - public GradeListDialog(DialogCallBack.CallBack callBack) { | |
36 | + private DialogCallBack.GradeCallBack mCallBack; | |
37 | + public GradeListDialog(DialogCallBack.GradeCallBack callBack) { | |
38 | 38 | this.mCallBack = callBack; |
39 | 39 | } |
40 | - public static GradeListDialog getInstance(DialogCallBack.CallBack callBack) { | |
40 | + public static GradeListDialog getInstance(DialogCallBack.GradeCallBack callBack) { | |
41 | 41 | GradeListDialog dialogFragment = new GradeListDialog(callBack); |
42 | 42 | dialogFragment.setCanceledBack(true); |
43 | 43 | dialogFragment.setCanceledOnTouchOutside(true); |
... | ... | @@ -80,7 +80,7 @@ public class GradeListDialog extends BaseCircleDialog implements AdapterView.OnI |
80 | 80 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
81 | 81 | |
82 | 82 | SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.GRADENS, ""+data.get(position).getId()); |
83 | - mCallBack.provinceOnItemClick(parent,view,position,id,5); | |
83 | + mCallBack.province3OnItemClick(data,position,5); | |
84 | 84 | dismiss(); |
85 | 85 | |
86 | 86 | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/ProvinceListDialog.java
... | ... | @@ -35,7 +35,7 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
35 | 35 | private ListView listView; |
36 | 36 | private ArrayList<ProvinceInfo.ProvincesBean> data = new ArrayList<>(); |
37 | 37 | |
38 | - private DialogCallBack.CallBack mCallBack; | |
38 | + private DialogCallBack.ProvincesCallBack mCallBack; | |
39 | 39 | |
40 | 40 | Handler handler = new Handler(){ |
41 | 41 | @Override |
... | ... | @@ -51,11 +51,11 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
51 | 51 | } |
52 | 52 | } |
53 | 53 | }; |
54 | - public ProvinceListDialog(DialogCallBack.CallBack callBack) { | |
54 | + public ProvinceListDialog(DialogCallBack.ProvincesCallBack callBack) { | |
55 | 55 | this.mCallBack = callBack; |
56 | 56 | } |
57 | 57 | |
58 | - public static ProvinceListDialog getInstance(DialogCallBack.CallBack callBack) { | |
58 | + public static ProvinceListDialog getInstance(DialogCallBack.ProvincesCallBack callBack) { | |
59 | 59 | ProvinceListDialog dialogFragment = new ProvinceListDialog(callBack); |
60 | 60 | dialogFragment.setCanceledBack(true); |
61 | 61 | dialogFragment.setCanceledOnTouchOutside(true); |
... | ... | @@ -86,7 +86,7 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
86 | 86 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
87 | 87 | //Toast.makeText(getActivity(), "你点击了第" + position + "个", Toast.LENGTH_LONG).show(); |
88 | 88 | SaveParam.getInstance().saveLoginParam(getActivity(), SaveParam.PROVINCES, ""+data.get(position).getRegionId()); |
89 | - mCallBack.provinceOnItemClick(parent,view,position,id,1); | |
89 | + mCallBack.provinceOnItemClick(data,position,1); | |
90 | 90 | dismiss(); |
91 | 91 | |
92 | 92 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/SchoolListDialog.java
... | ... | @@ -39,16 +39,16 @@ public class SchoolListDialog extends BaseCircleDialog implements AdapterView.On |
39 | 39 | private View mView; |
40 | 40 | boolean isFilter; |
41 | 41 | ArrayList<SchoolInfo.DataBean> data = new ArrayList<>(); |
42 | - private DialogCallBack.CallBack mCallBack; | |
42 | + private DialogCallBack.SchoolCallBack mCallBack; | |
43 | 43 | |
44 | 44 | // public SchoolListDialog(DialogCallBack.CallBackView callBack) { |
45 | 45 | // this.mCallBack = callBack; |
46 | 46 | // } |
47 | - public SchoolListDialog(DialogCallBack.CallBack callBack) { | |
47 | + public SchoolListDialog(DialogCallBack.SchoolCallBack callBack) { | |
48 | 48 | this.mCallBack = callBack; |
49 | 49 | } |
50 | 50 | |
51 | - public static SchoolListDialog getInstance(DialogCallBack.CallBack mCallBack) { | |
51 | + public static SchoolListDialog getInstance(DialogCallBack.SchoolCallBack mCallBack) { | |
52 | 52 | SchoolListDialog dialogFragment = new SchoolListDialog(mCallBack); |
53 | 53 | dialogFragment.setCanceledBack(true); |
54 | 54 | dialogFragment.setCanceledOnTouchOutside(true); |
... | ... | @@ -128,7 +128,7 @@ public class SchoolListDialog extends BaseCircleDialog implements AdapterView.On |
128 | 128 | |
129 | 129 | @Override |
130 | 130 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
131 | - mCallBack.provinceOnItemClick(parent,view,position,id,4); | |
131 | + mCallBack.provinceO4nItemClick(data,position,4); | |
132 | 132 | dismiss(); |
133 | 133 | |
134 | 134 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/http/HttpManager.java
... | ... | @@ -42,6 +42,7 @@ import org.json.JSONException; |
42 | 42 | import org.json.JSONObject; |
43 | 43 | |
44 | 44 | import java.io.UnsupportedEncodingException; |
45 | +import java.util.ArrayList; | |
45 | 46 | import java.util.List; |
46 | 47 | |
47 | 48 | public class HttpManager { |
... | ... | @@ -683,14 +684,25 @@ public class HttpManager { |
683 | 684 | public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { |
684 | 685 | Log.e("test", "年级" + new String(arg2)); |
685 | 686 | GradeInfo gradeInfo = GsonTool.getPerson(new String(arg2), GradeInfo.class);//解析json数据 |
686 | - List<GradeInfo.DataBean.ChildrenBean> gradeInfoBeanList = null; | |
687 | - for (int i = 0 ;i<3;i++) { | |
688 | - gradeInfoBeanList=(gradeInfo.getData().get(i).getChildren()); | |
687 | + List<GradeInfo.DataBean.ChildrenBean> gradeInfoLists = new ArrayList<GradeInfo.DataBean.ChildrenBean>(); | |
688 | + for (int i = 0 ;i<gradeInfo.getData().size()-2;i++) { | |
689 | + String name = gradeInfo.getData().get(i).getName(); | |
690 | + int id = gradeInfo.getData().get(i).getId(); | |
691 | + List<GradeInfo.DataBean.ChildrenBean> gradeinfoList = gradeInfo.getData().get(i).getChildren(); | |
692 | + for (int j = 0; j < gradeinfoList.size(); j++) { | |
693 | + String secondname = gradeinfoList.get(j).getName(); | |
694 | + int secondid = gradeinfoList.get(j).getId(); | |
695 | + GradeInfo.DataBean.ChildrenBean dataBean = new GradeInfo.DataBean.ChildrenBean(); | |
696 | + dataBean.setName(secondname); | |
697 | + dataBean.setId(secondid); | |
698 | + gradeInfoLists.add(dataBean); | |
699 | + } | |
700 | + | |
689 | 701 | } |
690 | 702 | |
691 | 703 | Message message = Message.obtain(); |
692 | 704 | message.what = HttpCode.GRADER; |
693 | - message.obj = gradeInfoBeanList; | |
705 | + message.obj = gradeInfoLists; | |
694 | 706 | handler.sendMessage(message); |
695 | 707 | |
696 | 708 | |
... | ... | @@ -722,7 +734,14 @@ public class HttpManager { |
722 | 734 | } |
723 | 735 | }); |
724 | 736 | } |
725 | - ///获取学校 | |
737 | + | |
738 | + /** | |
739 | + * 获取学校 | |
740 | + * @param mContext | |
741 | + * @param regionId | |
742 | + * @param gradeId | |
743 | + * @param handler | |
744 | + */ | |
726 | 745 | public void getschool(final Context mContext, int regionId, int gradeId, final Handler handler) { |
727 | 746 | HttpClient.getInstance().addHeader("Accept", "application/json"); |
728 | 747 | HttpClient.getInstance().get(HttpUrl.schoolUrl+ "?regionId=" + regionId+ "&gradeId=" + gradeId, new AsyncHttpResponseHandler() { | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/interfaces/DialogCallBack.java
... | ... | @@ -4,14 +4,34 @@ import android.content.Context; |
4 | 4 | import android.view.View; |
5 | 5 | import android.widget.AdapterView; |
6 | 6 | |
7 | +import com.hjx.personalcenter.model.CityInfo; | |
8 | +import com.hjx.personalcenter.model.CountyInfo; | |
9 | +import com.hjx.personalcenter.model.GradeInfo; | |
10 | +import com.hjx.personalcenter.model.ProvinceInfo; | |
11 | +import com.hjx.personalcenter.model.SchoolInfo; | |
12 | + | |
13 | +import java.util.ArrayList; | |
14 | + | |
7 | 15 | /** |
8 | 16 | * Created by wei on 2017/8/17. |
9 | 17 | */ |
10 | 18 | |
11 | 19 | public class DialogCallBack { |
12 | 20 | //对话框回调 |
13 | - public interface CallBack{ | |
14 | - void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id,int type); | |
21 | + public interface ProvincesCallBack{ | |
22 | + void provinceOnItemClick(ArrayList<ProvinceInfo.ProvincesBean> data, int position, int type); | |
23 | + } | |
24 | + public interface CitysCallBack{ | |
25 | + void province1OnItemClick(ArrayList<CityInfo.CitiesBean> data, int position, int type); | |
26 | + } | |
27 | + public interface CountryCallBack{ | |
28 | + void province2OnItemClick(ArrayList<CountyInfo.CountiesBean> data, int position, int type); | |
29 | + } | |
30 | + public interface GradeCallBack{ | |
31 | + void province3OnItemClick(ArrayList<GradeInfo.DataBean.ChildrenBean> data, int position, int type); | |
32 | + } | |
33 | + public interface SchoolCallBack{ | |
34 | + void provinceO4nItemClick(ArrayList<SchoolInfo.DataBean> data, int position, int type); | |
15 | 35 | } |
16 | 36 | //头像回调 |
17 | 37 | public interface CallBackView{ | ... | ... |