2 回答
TA贡献2041条经验 获得超4个赞
用这个
public class AdapterForNamesListInUpcoming extends RecyclerView.Adapter<AdapterForNamesListInUpcoming.SingleItemRowHolder> {
private List<SingleItemModelForUpcoming> itemsList;
private List<SingleItemforPhoneNumbers> itemforPhoneNumbers;
private ArrayList<UpcomingObject> item;
private Context mContext;
public AdapterForNamesListInUpcoming(Context context,ArrayList<UpcomingObject> item, List<SingleItemforPhoneNumbers> itemforPhoneNumbers , List<SingleItemModelForUpcoming> itemsList ) {
this.itemsList = itemsList;
this.item = item;
this.itemforPhoneNumbers = itemforPhoneNumbers;
this.mContext = context;
}
@Override
public SingleItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.upcomingclientlistlayout, null);
SingleItemRowHolder mh = new SingleItemRowHolder(v);
return mh;
}
@Override
public void onBindViewHolder(SingleItemRowHolder holder, int i) {
SingleItemModelForUpcoming singleItem = itemsList.get(i);
SingleItemforPhoneNumbers singleItemforPhoneNumbers = itemforPhoneNumbers.get(i);
holder.nameofclient.setText(singleItem.getName());
holder.phoneNumber.setText(singleItemforPhoneNumbers.getPhoneNumber());
}
@Override
public int getItemCount() {
return (null != itemsList ? itemsList.size() : 0);
}
public class SingleItemRowHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
protected TextView nameofclient , phoneNumber, date;
public SingleItemRowHolder(View view) {
super(view);
this.nameofclient = (TextView) view.findViewById(R.id.nameofclient);
this.phoneNumber = (TextView)view.findViewById(R.id.phoneNumber);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UpcomingObject up = item.get(getAdapterPosition);
Intent UpcomingDetailPage = new Intent(v.getContext(), com.allwaseet.spaservshop.UpcomingDetailsPage.UpcomingDetailPage.class);
v.getContext().startActivity(UpcomingDetailPage);
String finalPhoneNumber = phoneNumber.getText().toString();
Log.d("PhoneNumber from databse ","phone Number is "+finalPhoneNumber);
SharedPreferences.Editor PhoneNumberEditor;
SharedPreferences PhoneNumberSharedPreference;
PhoneNumberSharedPreference = mContext.getSharedPreferences("SelectedPhoneNumber", Context.MODE_PRIVATE);
PhoneNumberEditor = PhoneNumberSharedPreference.edit();
PhoneNumberEditor.putString("SelectedPhoneNumber",finalPhoneNumber);
PhoneNumberEditor.commit();
Log.d("PhoneNumber from databse ","phone Number is "+finalPhoneNumber);
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.upcominglayout, null, true);
TextView textView = (TextView)view.findViewById( R.id.date );
String finaldate = textView.getText().toString();
Log.d("ss","date is "+finaldate);
SharedPreferences.Editor DateEditor;
SharedPreferences DateSharedPreference;
DateSharedPreference = mContext.getSharedPreferences("DateInUpcoming", Context.MODE_PRIVATE);
DateEditor = DateSharedPreference.edit();
DateEditor.putString("DateInUpcoming",finaldate);
DateEditor.commit();
// return view;
}
});
}
}
}
TA贡献1887条经验 获得超5个赞
您可以使用Intent在按钮或任何项目的单击事件上将数据从一个类传递到另一个类,因此您可以将第一类的数据存储到共享首选项中,然后以键值对的形式传递数据,如下所示:
public class AdapterForNamesListInUpcoming extends
RecyclerView.Adapter<AdapterForNamesListInUpcoming.SingleItemRowHolder> {
private List<SingleItemModelForUpcoming> itemsList;
private List<SingleItemforPhoneNumbers> itemforPhoneNumbers;
private ArrayList<UpcomingObject> item;
private Context ctx;
public AdapterForNamesListInUpcoming(Context
context,ArrayList<UpcomingObject> item, List<SingleItemforPhoneNumbers>
itemforPhoneNumbers , List<SingleItemModelForUpcoming> itemsList ) {
this.itemsList = itemsList;
this.item = item;
this.itemforPhoneNumbers = itemforPhoneNumbers;
this.ctx = context;
}
@Override
public SingleItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v =
LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.upcomingclientlistlayout, null);
SingleItemRowHolder rh = new SingleItemRowHolder(v);
return rh;
}
@Override
public void onBindViewHolder(SingleItemRowHolder holder, int i) {
SingleItemModelForUpcoming singleItem = itemsList.get(i);
SingleItemforPhoneNumbers singleItemforPhoneNumbers =
itemforPhoneNumbers.get(i);
holder.nameofclient.setText(singleItem.getName());
holder.phoneNumber.setText(singleItemforPhoneNumbers.getPhoneNumber());
}
@Override
public int getItemCount() {
return (null != itemsList ? itemsList.size() : 0);
}
public class SingleItemRowHolder extends RecyclerView.ViewHolder implements
View.OnClickListener {
protected TextView nameofclient , phoneNumber, date;
public SingleItemRowHolder(View view) {
super(view);
this.nameofclient = (TextView) view.findViewById(R.id.nameofclient);
this.phoneNumber = (TextView)view.findViewById(R.id.phoneNumber);
view.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// get data of first adapter
UpcomingObject up = item.get(getAdapterPosition);
Intent UpcomingDetailPage = new Intent(v.getContext(),
com.allwaseet.spaservshop.UpcomingDetailsPage.UpcomingDetailPage.class);
v.getContext().startActivity(UpcomingDetailPage);
String finalPhoneNumber = phoneNumber.getText().toString();
Log.d("PhoneNumber from databse ","phone Number is "+finalPhoneNumber);
SharedPreferences.Editor PhoneNumberEditor;
SharedPreferences PhoneNumberSharedPreference;
PhoneNumberSharedPreference =
ctx.getSharedPreferences("SelectedPhoneNumber", Context.MODE_PRIVATE);
PhoneNumberEditor = PhoneNumberSharedPreference.edit();
PhoneNumberEditor.putString("SelectedPhoneNumber",finalPhoneNumber);
PhoneNumberEditor.commit();
Log.d("PhoneNumber from databse ","phone Number is "+finalPhoneNumber);
LayoutInflater inflater = LayoutInflater.from(ctx);
View view = inflater.inflate(R.layout.upcominglayout, null, true);
TextView textView = (TextView)view.findViewById( R.id.date );
String finaldate = textView.getText().toString();
Log.d("ss","date is "+finaldate);
SharedPreferences.Editor DateEditor;
SharedPreferences DateSharedPreference;
DateSharedPreference = ctx.getSharedPreferences("DateInUpcoming",
Context.MODE_PRIVATE);
DateEditor = DateSharedPreference.edit();
DateEditor.putString("DateInUpcoming",finaldate);
DateEditor.commit();
// return view;
}
}
}
添加回答
举报