У меня есть buyfragment
, у которого есть список элементов, добавленных в RecyclerView. Я хочу из другого фрагмента (sellfragment
) добавить новый элемент кнопкой вызова (startselling
) .. Так что мне просто нужен правильный код для метода lstDressAdd()
или для кнопки onClick (startselling
)
это (buyfragment
):
public class buyFragment extends Fragment {
public List<Dresses> lstDress;
RecyclerView myrv;
RecyclerViewAdapter myAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@ Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_buy, container, false);
lstDress = new ArrayList<>();
//DRESSES DATA
lstDress.add(new Dresses("flora V-neck Drawstring A-line dress", "Bersheka", "new", 150.0, R.drawable.dress22));
lstDress.add(new Dresses("Button front flounce waist floral dress", "Pull&Bear", "new", 200.0, R.drawable.dress2));
lstDress.add(new Dresses("Shirred waist split hem Flower print dress", "Stradivarius", "new", 199.0, R.drawable.dress1));
lstDress.add(new Dresses("flora print square neck split hem midi dress", "MANGO", "new", 175.0, R.drawable.e));
lstDress.add(new Dresses("confetti heart surplice neck knot sleeve dress", "ZARA", "new", 168.0, R.drawable.dress22));
lstDress.add(new Dresses("flora V-neck Drawstring A-line dress", "ZARA", "new", 100.0, R.drawable.dress2));
lstDress.add(new Dresses("Shirred waist split hem Flower print dress", "Stradivuse", "new", 199.0, R.drawable.dress1));
myrv = (RecyclerView) view.findViewById(R.id.recyclerviwe_id);
myAdapter = (new RecyclerViewAdapter(getContext(), lstDress));
myrv.setLayoutManager(new GridLayoutManager(getActivity(), 2));
myrv.setAdapter(myAdapter);
return view;
}
public void lstDressAdd(String dress_title, String brand, String use, Double price) {
lstDress.add(new Dresses(dress_title, brand, use, price, R.drawable.dress1));
}}
и это (sellfragment):
startselling=(Button)view.findViewById(R.id.button3) ;
startselling.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = brands.getSelectedItem().toString();
String Use;
if(newradio.getText().toString()=="New dress")
Use="New";
else
Use="Used";
String d=dress_title.getText().toString();
Double p=Double.parseDouble(price.getText().toString());
if(d==null &&p==null&&Use==null&&text==null){
Toast.makeText(getContext(), "you need to complete the dress Info", Toast.LENGTH_SHORT).show();
}else{
buyFragment n=new buyFragment();
n.lstDressAdd(dress_title.getText().toString(),text,Use,Double.parseDouble(price.getText().toString()));
Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();}
}
});
пожалуйста, помогите мне, это мой проект колледжа и дата через два дня