Android 从RecycleServiceAdapter中的生成器模式获取值
实际上,当接收到JSON响应时,我的同事使用构建器模式(implements Parcelable)而不是getter和setter,因此我想实现RecycleServiceAdapter类来创建listView。。。 那么有谁能帮助我如何使用RecycleServiceAdapter中的Builder模式类来呈现我们的ListView呢 注:Android 从RecycleServiceAdapter中的生成器模式获取值,android,listview,android-recyclerview,android-arrayadapter,builder-pattern,Android,Listview,Android Recyclerview,Android Arrayadapter,Builder Pattern,实际上,当接收到JSON响应时,我的同事使用构建器模式(implements Parcelable)而不是getter和setter,因此我想实现RecycleServiceAdapter类来创建listView。。。 那么有谁能帮助我如何使用RecycleServiceAdapter中的Builder模式类来呈现我们的ListView呢 注: 我知道如果他使用getter和setter,我该怎么做,但我不知道Builder模式的概念 我也知道这个包裹是用来把物品从一个活动传递到另一个活动的,但
public class ServiceProviderAdapter extends RecyclerView.Adapter<ServiceProviderAdapter.ViewHolder>{
ArrayList<ProviderItem> mItemsList;
Context context;
public ServiceProviderAdapter(ArrayList<ProviderItem> mItemsList,Context context){
super();
this.mItemsList = mItemsList;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_find,parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ProviderItem providerItem= mItemsList.get(position);
// holder.ServiceCentreName.setText();
//how to get the Data from the Builder Pattern class... again i know how to use getter setter but i don't know how to retreive from the Builder class
}
@Override
public int getItemCount() {
return mItemsList.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public TextView ServiceCentreName,ServiceCentreAddress,CentreDistance,ServicePrice;
public RatingBar ratingBar;
public ViewHolder(View itemView) {
super(itemView);
ServiceCentreName=(TextView)itemView.findViewById(R.id.ServiceproviderName);
ServiceCentreAddress=(TextView)itemView.findViewById(R.id.ServiceproviderAddress);
CentreDistance=(TextView)itemView.findViewById(R.id.ServiceproviderDistance);
ServicePrice=(TextView)itemView.findViewById(R.id.service_price);
ratingBar=(RatingBar)itemView.findViewById(R.id.ServiceProviderRating);
}
}
}
在主活动中:
填充我使用的数据之后
ArrayList<ServiceProviderItem> workshopList;
mAdapter=new ServiceProviderAdapter(this,workshopList);
mRecyclerView.setAdapter(mAdapter);
//volley on response, i used the below code for populating...If i wrong please correct me
JSONObject item = workshops.getJSONObject(i);
ServiceProviderItem serviceProvider = new ServiceProviderItem(new ServiceProviderItem.Builder(
Const.TAG_WORKSHOP_ID, Const.TAG_CITY, Const.TAG_WORKSHOP_NAME, Const.TAG_LAT, Const.TAG_LON, Const.TAG_LOGO, Const.TAG_ID_CAR).optional(
Const.TAG_LOCALITIES,
Const.TAG_ADDRESS
});
ArrayList工作区列表;
mAdapter=新服务提供商适配器(此为工作区列表);
mRecyclerView.setAdapter(mAdapter);
//截击的回应,我使用下面的代码填充…如果我错了,请纠正我
JSONObject项=workshops.getJSONObject(i);
ServiceProviderItem serviceProvider=新ServiceProviderItem(新ServiceProviderItem.Builder(
Const.TAG\u车间标识、Const.TAG\u城市、Const.TAG\u车间名称、Const.TAG\u LAT、Const.TAG\u LON、Const.TAG\u徽标、Const.TAG\u标识车)。可选(
Const.TAG_地区,
常量标记地址
});
在服务提供商适配器中:
public class ServiceProviderAdapter extends RecyclerView.Adapter<ServiceProviderAdapter.ViewHolder>{
ArrayList<ProviderItem> mItemsList;
Context context;
public ServiceProviderAdapter(ArrayList<ProviderItem> mItemsList,Context context){
super();
this.mItemsList = mItemsList;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_find,parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ProviderItem providerItem= mItemsList.get(position);
// holder.ServiceCentreName.setText();
//how to get the Data from the Builder Pattern class... again i know how to use getter setter but i don't know how to retreive from the Builder class
}
@Override
public int getItemCount() {
return mItemsList.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public TextView ServiceCentreName,ServiceCentreAddress,CentreDistance,ServicePrice;
public RatingBar ratingBar;
public ViewHolder(View itemView) {
super(itemView);
ServiceCentreName=(TextView)itemView.findViewById(R.id.ServiceproviderName);
ServiceCentreAddress=(TextView)itemView.findViewById(R.id.ServiceproviderAddress);
CentreDistance=(TextView)itemView.findViewById(R.id.ServiceproviderDistance);
ServicePrice=(TextView)itemView.findViewById(R.id.service_price);
ratingBar=(RatingBar)itemView.findViewById(R.id.ServiceProviderRating);
}
}
}
公共类ServiceProviderAdapter扩展了RecyclerView.Adapter{
阵列列表;
语境;
公共服务提供者适配器(ArrayList mItemsList,上下文){
超级();
this.mItemsList=mItemsList;
this.context=上下文;
}
@凌驾
public ViewHolder onCreateViewHolder(视图组父级,int-viewType){
视图v=LayoutInflater.from(parent.getContext()).flate(R.layout.content\u find,parent,false);
视窗夹持器视窗夹持器=新视窗夹持器(v);
返回视图持有者;
}
@凌驾
公共无效onBindViewHolder(ViewHolder,int位置){
ProviderItem ProviderItem=mItemsList.get(位置);
//holder.ServiceCentreName.setText();
//如何从构建器模式类中获取数据……同样,我知道如何使用getter setter,但我不知道如何从构建器类中检索数据
}
@凌驾
public int getItemCount(){
返回mItemsList.size();
}
类ViewHolder扩展了RecyclerView.ViewHolder{
公共文本视图ServiceCentreName、ServiceCentreAddress、CentreInstance、ServicePrice;
公共评级杆评级杆;
公共视图持有者(视图项视图){
超级(项目视图);
ServiceCentreName=(TextView)itemView.findViewById(R.id.ServiceproviderName);
ServiceCentreAddress=(TextView)itemView.findViewById(R.id.ServiceproviderAddress);
CentreInstance=(TextView)itemView.findViewById(R.id.ServiceproviderDistance);
ServicePrice=(TextView)itemView.findViewById(R.id.service\u price);
ratingBar=(ratingBar)itemView.findViewById(R.id.ServiceProviderRating);
}
}
}
在服务提供商项目中:
public class ServiceProviderAdapter extends RecyclerView.Adapter<ServiceProviderAdapter.ViewHolder>{
ArrayList<ProviderItem> mItemsList;
Context context;
public ServiceProviderAdapter(ArrayList<ProviderItem> mItemsList,Context context){
super();
this.mItemsList = mItemsList;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.content_find,parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
ProviderItem providerItem= mItemsList.get(position);
// holder.ServiceCentreName.setText();
//how to get the Data from the Builder Pattern class... again i know how to use getter setter but i don't know how to retreive from the Builder class
}
@Override
public int getItemCount() {
return mItemsList.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public TextView ServiceCentreName,ServiceCentreAddress,CentreDistance,ServicePrice;
public RatingBar ratingBar;
public ViewHolder(View itemView) {
super(itemView);
ServiceCentreName=(TextView)itemView.findViewById(R.id.ServiceproviderName);
ServiceCentreAddress=(TextView)itemView.findViewById(R.id.ServiceproviderAddress);
CentreDistance=(TextView)itemView.findViewById(R.id.ServiceproviderDistance);
ServicePrice=(TextView)itemView.findViewById(R.id.service_price);
ratingBar=(RatingBar)itemView.findViewById(R.id.ServiceProviderRating);
}
}
}
公共类提供程序实现了Parcelable{
String workshop_id, city, workshop_name, localities, address, phone, email, lat, lon, working_day, timings, active_flag, logo, service, repair,
carwash, discount, id_car;
public Provider(Builder builder)
{
this.workshop_id = builder.workshop_id;
this.city = builder.city;
this.workshop_name = builder.workshop_name;
this.localities = builder.workshop_name;
....
}
protected Provider(Parcel in)
{
this.workshop_id = in.readString();
this.city = in.readString();
this.workshop_name = in.readString();
this.localities = in.readString();
......
}
@Override
public int describeContents() {
return hashCode();
}
@Override
public void writeToParcel(Parcel dest, int flags)
{
dest.writeString(workshop_id);
dest.writeString(city);
dest.writeString(workshop_name);
dest.writeString(localities);
....
}
public static final Creator<Provider> CREATOR = new Creator<Provider>() {
@Override
public Provider createFromParcel(Parcel in) {
return new Provider(in);
}
@Override
public Provider[] newArray(int size) {
return new Provider[size];
}
};
public static class Builder
{
String workshop_id, city, workshop_name, localities, address, phone, email, lat, lon, working_day, timings, active_flag, logo, service, repair,
carwash, discount, id_car;
public Builder(String workshop_id, String city, String workshop_name, String lat, String lon, String logo, String id_car)
{
this.workshop_id = workshop_id;
this.city = city;
this.workshop_name = workshop_name;
this.lat = lat;
this.lon = lon;
this.logo = logo;
this.id_car = id_car;
....
}
public Builder localities(String localities) {
this.localities = localities;
return this;
}
public Builder address(String address) {
this.address = address;
return this;
}
public Builder phone(String phone) {
this.phone = phone;
return this;
}
public Builder email(String email) {
this.email = email;
return this;
}
public Builder working_day(String working_day) {
this.working_day = working_day;
return this;
}
public Builder timings(String timings) {
this.timings = timings;
return this;
}
public Builder active_flag(String active_flag) {
this.active_flag = active_flag;
return this;
}
public Builder service(String service) {
this.service = service;
return this;
}
public Builder repair(String repair) {
this.repair = repair;
return this;
}
public Builder carwash(String carwash) {
this.carwash = carwash;
return this;
}
public Builder discount(String discount) {
this.discount = discount;
return this;
}
public Builder optional(String localities, String address, String phone, String email, String working_day, String timings, String active_flag,
String service, String repair, String carwash, String discount) {
this.localities = localities;
this.address = address;
this.phone = phone;
this.email = email;
this.working_day = working_day;
this.timings = timings;
this.active_flag = active_flag;
this.service = service;
this.repair = repair;
this.carwash = carwash;
this.discount = discount;
return this;
}
public Provider Build()
{
return new Provider(this);
}
}
}
字符串车间id、城市、车间名称、地点、地址、电话、电子邮件、lat、lon、工作日、计时、活动标志、徽标、服务、维修、,
洗车、折扣、身份证车;
公共提供商(建筑商)
{
this.workshop\u id=builder.workshop\u id;
this.city=builder.city;
this.workshop\u name=builder.workshop\u name;
this.localities=builder.workshop\u name;
....
}
受保护的提供程序(包裹输入)
{
this.workshop_id=in.readString();
this.city=in.readString();
this.workshop_name=in.readString();
this.localities=in.readString();
......
}
@凌驾
公共int描述内容(){
返回hashCode();
}
@凌驾
公共无效写入包裹(包裹目的地,内部标志)
{
目的地记录(车间标识);
目的地登记册(城市);
目的书面记录(车间名称);
目的地登记(地方);
....
}
公共静态最终创建者=新创建者(){
@凌驾
公共提供程序createFromParcel(中的地块){
返回新的提供者(在中);
}
@凌驾
公共提供程序[]新数组(整数大小){
返回新的提供者[大小];
}
};
公共静态类生成器
{
字符串车间id、城市、车间名称、地点、地址、电话、电子邮件、lat、lon、工作日、计时、活动标志、徽标、服务、维修、,
洗车、折扣、身份证车;
公共建筑商(字符串车间标识、字符串城市、字符串车间名称、字符串lat、字符串lon、字符串徽标、字符串标识车)
{
this.workshop\u id=workshop\u id;
this.city=城市;
this.workshop\u name=workshop\u name;
this.lat=lat;
this.lon=lon;
this.logo=logo;
this.id\u car=id\u car;
....
}
公共生成器位置(字符串位置){
this.localies=localies;
归还这个;
}
公共生成器地址(字符串地址){
this.address=地址;
归还这个;
}
公共构建器电话(字符串电话){
this.phone=电话;
归还这个;
}
公共生成器电子邮件(字符串电子邮件){
this.email=电子邮件;
归还这个;
}
公共建筑商工作日(字符串工作日){
this.working_day=working_day;
归还这个;
}
公共生成器计时(字符串计时){
this.timings=计时;
归还这个;
}
公共生成器活动\u标志(字符串活动\u标志){
this.active\u flag=active\u flag;
归还这个;
}
公共生成器服务(字符串服务){
服务=服务;
归还这个;
}
公共建筑商维修(管柱维修){
这个。修理=修理;
归还这个;
}
公共建筑商洗车(串洗车){
this.carwash=carwash;