Answer the question
In order to leave comments, you need to log in
How to pass data from Custom layout to activity layout?
This is a custom layout , I don't know how to pass data to another activity (which is not MainActivity) here I pass the quantity to the cart. The cart is in (( Dialog_lay1 )getActivity()).txt_siparis1.setText(input); //???
plz help and thanks for your time.
public class Asma1 extends DialogFragment implements View.OnClickListener {
public TextView adet_asma;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View mview = inflater.inflate(R.layout.asma1, null);
adet_asma = mview.findViewById(R.id.text_value);
mview.findViewById(R.id.imageButtonPlus).setOnClickListener(v -> {
TvPlus_Minus++;
adet_asma.setText(String.valueOf(TvPlus_Minus));
});
mview.findViewById(R.id.imageButtonMinus).setOnClickListener(v -> {
TvPlus_Minus--;
adet_asma.setText(String.valueOf(TvPlus_Minus));
});
mview.findViewById(R.id.imageButtonclose1).setOnClickListener(v -> {
dismiss(); //close dialog
});
mview.findViewById(R.id.on_siparis).setOnClickListener(v -> {
String input = adet_asma.getText().toString();
if(!input.equals("")) {
((Dialog_lay1)getActivity()) .txt_siparis1.setText(input); //???
Toast toast = Toast.makeText(getContext(), "order added to list", Toast.LENGTH_LONG);
toast.show();
dismiss();
}
else{
Toast.makeText(getActivity(),"o", Toast.LENGTH_LONG).show();
}
});
return view;
//////////////////////////////////Dialog_lay1//////////////// ///
public class Dialog_lay1 extends AppCompatActivity implements View.OnClickListener {
ImageButton close_dialog;
public TextView txt_siparis1;
public TextView adi_asma1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_lay1);
close_dialog = findViewById(R.id.close_dialog);
close_dialog.setOnClickListener(this);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
txt_siparis1 = findViewById(R.id.text_siparis);
adi_asma1 = findViewById(R.id.adet1);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question