dimanche 20 décembre 2020

there is an unexpected result for the if statement in android studio, why?

in my expandable list view I wrote the (if) statement that returns a (dialog) if two words are contained in the child Row ..

and here is the code:

.......
    childObjects.add(new ChildObject(cetamol + " " + syr + " 160 " + mg5ml
                , cetamolDoseMini160));
    ..........



    elv = findViewById(R.id.elv);
    elv.setOnGroupExpandListener(onGroupExpandListenser);

    MyExpandableAdapter adapter = new MyExpandableAdapter(this, getData());
    elv.setAdapter(adapter);

    elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

            for (int i = 0; i < ((ViewGroup) v).getChildCount(); ++i) {
                View nextChild = ((ViewGroup) v).getChildAt(i);
                if (nextChild.getId() == R.id.txtChildName) {
                    String data = ((TextView) nextChild).getText().toString();

                    String paracetamol = getResources().getString(R.string.Paracetamol);

                
                    if (data.contains(paracetamol)|| data.contains("160")) {

                        AlertDialog.Builder builder = new AlertDialog.Builder(Analgesics.this);

                        builder.setTitle(" Paracetamol 160:");

                        String[] drugsTrades = {"Hayamol 160 ", "Paradrin 160 "};

                        builder.setItems(drugsTrades, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        });
                        AlertDialog dialog = builder.create();
                        // dialog.getWindow().setBackgroundDrawableResource(R.color.translucent_black);
                        dialog.show();
                    }

                }
            }
                return true;
            }
    });

but the (if statement) saw (just) the first part "paracetamol" and didn't see the second part "160"

Aucun commentaire:

Enregistrer un commentaire