Commit a41324295d38312bb7ee84e8cefdb159e5bbf892
1 parent
c2f64dd6c9
Exists in
master
回调接口的使用
Showing
8 changed files
with
132 additions
and
19 deletions
Show diff stats
PersonalCenter/.idea/inspectionProfiles/Project_Default.xml
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +<component name="InspectionProjectProfileManager"> | |
| 2 | + <profile version="1.0"> | |
| 3 | + <option name="myName" value="Project Default" /> | |
| 4 | + <inspection_tool class="AndroidLintValidFragment" enabled="false" level="ERROR" enabled_by_default="false" /> | |
| 5 | + <inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false"> | |
| 6 | + <option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" /> | |
| 7 | + <option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" /> | |
| 8 | + </inspection_tool> | |
| 9 | + </profile> | |
| 10 | +</component> | |
| 0 | 11 | \ No newline at end of file | ... | ... |
PersonalCenter/.idea/inspectionProfiles/profiles_settings.xml
| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | +<component name="InspectionProjectProfileManager"> | |
| 2 | + <settings> | |
| 3 | + <option name="PROJECT_PROFILE" value="Project Default" /> | |
| 4 | + <option name="USE_PROJECT_PROFILE" value="true" /> | |
| 5 | + <version value="1.0" /> | |
| 6 | + </settings> | |
| 7 | +</component> | |
| 0 | 8 | \ No newline at end of file | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/activity/RegisterInfoActivity.java
| ... | ... | @@ -4,6 +4,7 @@ import android.content.Intent; |
| 4 | 4 | import android.os.Bundle; |
| 5 | 5 | import android.support.v7.app.AppCompatActivity; |
| 6 | 6 | import android.view.View; |
| 7 | +import android.widget.AdapterView; | |
| 7 | 8 | import android.widget.Button; |
| 8 | 9 | import android.widget.EditText; |
| 9 | 10 | import android.widget.TextView; |
| ... | ... | @@ -12,12 +13,13 @@ import com.hjx.personalcenter.R; |
| 12 | 13 | import com.hjx.personalcenter.customdialog.GradeListDialog; |
| 13 | 14 | import com.hjx.personalcenter.customdialog.ProvinceListDialog; |
| 14 | 15 | import com.hjx.personalcenter.http.HttpManager; |
| 16 | +import com.hjx.personalcenter.interfaces.DialogCallBack; | |
| 15 | 17 | |
| 16 | 18 | /**填写注册信息 熊巍 |
| 17 | 19 | * Created by h on 2017/8/9. |
| 18 | 20 | */ |
| 19 | 21 | |
| 20 | -public class RegisterInfoActivity extends AppCompatActivity implements View.OnClickListener { | |
| 22 | +public class RegisterInfoActivity extends AppCompatActivity implements View.OnClickListener,DialogCallBack.CallBack { | |
| 21 | 23 | private EditText et_username; |
| 22 | 24 | private TextView et_region,et_grade,et_school; |
| 23 | 25 | private Button btn_ok; |
| ... | ... | @@ -79,11 +81,22 @@ public class RegisterInfoActivity extends AppCompatActivity implements View.OnCl |
| 79 | 81 | //选择地区 |
| 80 | 82 | private void choiseregion() { |
| 81 | 83 | HttpManager.getInstance().provices(RegisterInfoActivity.this); |
| 82 | - ProvinceListDialog.getInstance().show(getSupportFragmentManager(), "ProvinceListDialog"); | |
| 84 | + ProvinceListDialog.getInstance(this).show(getSupportFragmentManager(), "ProvinceListDialog"); | |
| 85 | + | |
| 83 | 86 | } |
| 84 | 87 | //选择年级 |
| 85 | 88 | private void choisegrade() { |
| 86 | 89 | GradeListDialog.getInstance().show(getSupportFragmentManager(), "GradeListDialog"); |
| 87 | 90 | |
| 88 | 91 | } |
| 92 | + | |
| 93 | + @Override | |
| 94 | + public void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id) { | |
| 95 | + | |
| 96 | + View gradeView = parent.getChildAt(position); | |
| 97 | + TextView gradeTv = (TextView)gradeView.findViewById(R.id.list_items); | |
| 98 | + et_region.setText(gradeTv.getText().toString()); | |
| 99 | + | |
| 100 | + | |
| 101 | + } | |
| 89 | 102 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/adapter/ProvincesAdapter.java
| ... | ... | @@ -0,0 +1,65 @@ |
| 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.ProvinceInfo; | |
| 11 | + | |
| 12 | +import java.util.ArrayList; | |
| 13 | + | |
| 14 | +/** | |
| 15 | + * Created by l on 2017/7/18. | |
| 16 | + */ | |
| 17 | + | |
| 18 | +public class ProvincesAdapter extends BaseAdapter { | |
| 19 | + ArrayList<ProvinceInfo.ProvincesBean> objects; | |
| 20 | + private Context context; | |
| 21 | + | |
| 22 | + public ProvincesAdapter(ArrayList<ProvinceInfo.ProvincesBean> objects, Context context) { | |
| 23 | + this.objects = objects; | |
| 24 | + this.context = context; | |
| 25 | + } | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + public int getCount() { | |
| 29 | + return objects.size(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public Object getItem(int position) { | |
| 34 | + return position; | |
| 35 | + } | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public long getItemId(int position) { | |
| 39 | + return position; | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public View getView(final int position, View convertView, ViewGroup parent) { | |
| 44 | + | |
| 45 | + ViewHolder holder = null; | |
| 46 | + | |
| 47 | + if (convertView == null) { | |
| 48 | + convertView = View.inflate(context, R.layout.custom_adilog_list_item, null); | |
| 49 | + holder = new ViewHolder(); | |
| 50 | + holder.nameText = (TextView) convertView.findViewById(R.id.list_items); | |
| 51 | + convertView.setTag(holder); | |
| 52 | + } else { | |
| 53 | + holder = (ProvincesAdapter.ViewHolder) convertView.getTag(); | |
| 54 | + } | |
| 55 | + | |
| 56 | + holder.nameText.setText(objects.get(position).getRegionName()); | |
| 57 | + | |
| 58 | + return convertView; | |
| 59 | + } | |
| 60 | + | |
| 61 | + | |
| 62 | + static class ViewHolder { | |
| 63 | + TextView nameText; | |
| 64 | + } | |
| 65 | +} | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/GradeListDialog.java
| ... | ... | @@ -57,6 +57,7 @@ public class GradeListDialog extends BaseCircleDialog implements AdapterView.OnI |
| 57 | 57 | |
| 58 | 58 | @Override |
| 59 | 59 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 60 | + | |
| 60 | 61 | Toast.makeText(getActivity(),"你点击了第"+position+"个",Toast.LENGTH_LONG).show(); |
| 61 | 62 | |
| 62 | 63 | dismiss(); | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/customdialog/ProvinceListDialog.java
| ... | ... | @@ -8,12 +8,14 @@ import android.view.LayoutInflater; |
| 8 | 8 | import android.view.View; |
| 9 | 9 | import android.view.ViewGroup; |
| 10 | 10 | import android.widget.AdapterView; |
| 11 | -import android.widget.ArrayAdapter; | |
| 12 | 11 | import android.widget.ListView; |
| 13 | 12 | |
| 14 | 13 | import com.hjx.personalcenter.R; |
| 14 | +import com.hjx.personalcenter.adapter.ProvincesAdapter; | |
| 15 | 15 | import com.hjx.personalcenter.db.SaveParam; |
| 16 | 16 | import com.hjx.personalcenter.http.HttpManager; |
| 17 | +import com.hjx.personalcenter.interfaces.DialogCallBack; | |
| 18 | +import com.hjx.personalcenter.model.ProvinceInfo; | |
| 17 | 19 | import com.mylhyl.circledialog.BaseCircleDialog; |
| 18 | 20 | import com.mylhyl.circledialog.res.values.CircleDimen; |
| 19 | 21 | |
| ... | ... | @@ -25,12 +27,18 @@ import java.util.ArrayList; |
| 25 | 27 | */ |
| 26 | 28 | |
| 27 | 29 | public class ProvinceListDialog extends BaseCircleDialog implements AdapterView.OnItemClickListener { |
| 28 | - ArrayAdapter listadapter; | |
| 29 | - ListView listView; | |
| 30 | - ArrayList<String> data = new ArrayList<>(); | |
| 30 | + private ProvincesAdapter listadapter; | |
| 31 | + private ListView listView; | |
| 32 | + private ArrayList<ProvinceInfo.ProvincesBean> data = new ArrayList<>(); | |
| 31 | 33 | |
| 32 | - public static ProvinceListDialog getInstance() { | |
| 33 | - ProvinceListDialog dialogFragment = new ProvinceListDialog(); | |
| 34 | + private DialogCallBack.CallBack mCallBack; | |
| 35 | + | |
| 36 | + public ProvinceListDialog(DialogCallBack.CallBack callBack) { | |
| 37 | + this.mCallBack = callBack; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public static ProvinceListDialog getInstance(DialogCallBack.CallBack callBack) { | |
| 41 | + ProvinceListDialog dialogFragment = new ProvinceListDialog(callBack); | |
| 34 | 42 | dialogFragment.setCanceledBack(true); |
| 35 | 43 | dialogFragment.setCanceledOnTouchOutside(true); |
| 36 | 44 | dialogFragment.setRadius(CircleDimen.RADIUS); |
| ... | ... | @@ -53,16 +61,15 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
| 53 | 61 | if (provinces != null) { |
| 54 | 62 | |
| 55 | 63 | for (int i = 0; i < provinces.split(",").length; i++) { |
| 56 | - String[] itmt = provinces.split(","); | |
| 57 | - data.add(itmt[i] + "省"); | |
| 58 | - //data.add(i,provinces.replaceAll(",","省")); | |
| 59 | - | |
| 64 | + ProvinceInfo.ProvincesBean provincesBean = new ProvinceInfo.ProvincesBean(); | |
| 65 | + provincesBean.setRegionName(provinces.split(",")[i] + "省"); | |
| 66 | + data.add(provincesBean); | |
| 60 | 67 | } |
| 61 | 68 | } else { |
| 62 | 69 | HttpManager.getInstance().provices(getActivity()); |
| 63 | 70 | } |
| 64 | 71 | |
| 65 | - listadapter = new ArrayAdapter(getActivity(), R.layout.custom_adilog_list_item, R.id.list_items, data); | |
| 72 | + listadapter = new ProvincesAdapter(data,getActivity()); | |
| 66 | 73 | listView.setAdapter(listadapter); |
| 67 | 74 | listView.setOnItemClickListener(this); |
| 68 | 75 | |
| ... | ... | @@ -71,12 +78,7 @@ public class ProvinceListDialog extends BaseCircleDialog implements AdapterView. |
| 71 | 78 | @Override |
| 72 | 79 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
| 73 | 80 | //Toast.makeText(getActivity(), "你点击了第" + position + "个", Toast.LENGTH_LONG).show(); |
| 74 | - switch (position){ | |
| 75 | - | |
| 76 | - } | |
| 77 | - | |
| 78 | - | |
| 79 | - | |
| 81 | + mCallBack.provinceOnItemClick(parent,view,position,id); | |
| 80 | 82 | dismiss(); |
| 81 | 83 | |
| 82 | 84 | } | ... | ... |
PersonalCenter/app/src/main/java/com/hjx/personalcenter/interfaces/DialogCallBack.java
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +package com.hjx.personalcenter.interfaces; | |
| 2 | + | |
| 3 | +import android.view.View; | |
| 4 | +import android.widget.AdapterView; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * Created by wei on 2017/8/17. | |
| 8 | + */ | |
| 9 | + | |
| 10 | +public class DialogCallBack { | |
| 11 | + public interface CallBack{ | |
| 12 | + void provinceOnItemClick(AdapterView<?> parent, View view, int position, long id); | |
| 13 | + } | |
| 14 | +} | ... | ... |