简体   繁体   中英

Every button click adds a dynamic layout to old layout ||Android||

I have checked everywhere but i couldn't find the answer. I am generating order details dynamically on every click. First click works fine,But after then, every click adds the new order to old order. Old one is not vanishing. I tried remove view but that did not help either. How can i fix that? I want to show every order detail when it is clicked.


@Override
    public void itemClicked(int index, int siparisId) {
        siparis_id = siparisId;

        getSiparisUrunleri(siparis_id);
    }



private void getSiparisDetay(int siparisId) {

linearUrunler = view.findViewById(R.id.linearUrunler);

        for (SiparisUrunleri siparisUrunleri : siparisUrunleriList) {

            linearTxt = new LinearLayout(context);
            linearTxt.setOrientation(LinearLayout.HORIZONTAL);
            linearTxt.setWeightSum(10f);
            linearTxt.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            TextView txtUrunAdi = new TextView(context);
            txtUrunAdi.setText(siparisUrunleri.getUrun_adi());
            txtUrunAdi.setId(siparisUrunleri.getId());
            txtUrunAdi.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 8f));
            txtUrunAdi.setPadding(3, 3, 3, 3);

            TextView txtUrunAdet = new TextView(context);
            txtUrunAdet.setId(siparisUrunleri.getId());
            txtUrunAdet.setText(MessageFormat.format("{0} Adet", siparisUrunleri.getAdet()));
            txtUrunAdet.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            txtUrunAdet.setPadding(3, 3, 3, 3);

            TextView txtUrunOlcu = new TextView(context);
            txtUrunOlcu.setId(siparisUrunleri.getId());
            txtUrunOlcu.setText(MessageFormat.format("{0}{1}", parseInputByReplace(siparisUrunleri.getOlcu()), getResources().getString(R.string.meter_square_sign)));
            txtUrunOlcu.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            txtUrunOlcu.setPadding(3, 3, 3, 3);

            linearTxt.addView(txtUrunAdi);
            linearTxt.addView(txtUrunAdet);
            linearTxt.addView(txtUrunOlcu);

            linearLayout.addView(linearTxt);
        }

        linearUrunler.addView(linearLayout);

 crdBtnX.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ((ViewGroup) linearUrunler.getParent()).removeView(linearLayout);

                relativeSiparisDetay.setVisibility(View.GONE);
            }
        });
}

siparisUrunleriList clears items every closing.

Try to use removeAllViewsInLayout(); for the parent layout,

for example:

linearLayout.removeAllViewsInLayout();

I have checked everywhere but i couldn't find the answer. I am generating order details dynamically on every click. First click works fine,But after then, every click adds the new order to old order. Old one is not vanishing. I tried remove view but that did not help either. How can i fix that? I want to show every order detail when it is clicked.


@Override
    public void itemClicked(int index, int siparisId) {
        siparis_id = siparisId;

        getSiparisUrunleri(siparis_id);
    }



private void getSiparisDetay(int siparisId) {

linearUrunler = view.findViewById(R.id.linearUrunler);

        for (SiparisUrunleri siparisUrunleri : siparisUrunleriList) {

            linearTxt = new LinearLayout(context);
            linearTxt.setOrientation(LinearLayout.HORIZONTAL);
            linearTxt.setWeightSum(10f);
            linearTxt.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

            TextView txtUrunAdi = new TextView(context);
            txtUrunAdi.setText(siparisUrunleri.getUrun_adi());
            txtUrunAdi.setId(siparisUrunleri.getId());
            txtUrunAdi.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 8f));
            txtUrunAdi.setPadding(3, 3, 3, 3);

            TextView txtUrunAdet = new TextView(context);
            txtUrunAdet.setId(siparisUrunleri.getId());
            txtUrunAdet.setText(MessageFormat.format("{0} Adet", siparisUrunleri.getAdet()));
            txtUrunAdet.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            txtUrunAdet.setPadding(3, 3, 3, 3);

            TextView txtUrunOlcu = new TextView(context);
            txtUrunOlcu.setId(siparisUrunleri.getId());
            txtUrunOlcu.setText(MessageFormat.format("{0}{1}", parseInputByReplace(siparisUrunleri.getOlcu()), getResources().getString(R.string.meter_square_sign)));
            txtUrunOlcu.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
            txtUrunOlcu.setPadding(3, 3, 3, 3);

            linearTxt.addView(txtUrunAdi);
            linearTxt.addView(txtUrunAdet);
            linearTxt.addView(txtUrunOlcu);

            linearLayout.addView(linearTxt);
        }

        linearUrunler.addView(linearLayout);

 crdBtnX.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                ((ViewGroup) linearUrunler.getParent()).removeView(linearLayout);

                relativeSiparisDetay.setVisibility(View.GONE);
            }
        });
}

siparisUrunleriList clears items every closing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM