Sending items to the database from an Array MultiChoice individually

0

I'm not a programmer, but I have a question and I can not find where to answer it.

I have a multichoice array, It turns out that when I get the "checkable" I can see them in a single String. I would like each item that is with its "check" to be saved in a different object, or if there is a way to separate the Strings from the only textView and then be sent to the database, it would be great.

The problem that I have is that everything I select is placed in the TextView in a linear way separated by a comma, and I would like that in addition to that, I can save them independently in the database. I am using AndroidStudio, and the database is Firebase Realtime Database

I hope someone can help me. Thanks in advance.

   profTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog.Builder mBuilder = new AlertDialog.Builder(Perfil.this);
                mBuilder.setTitle(R.string.profesi_n);
                mBuilder.setMultiChoiceItems(listItems, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int position, boolean isChecked) {
                        if(isChecked){
                            mProfesionItems.add(position);
                        }else{
                            mProfesionItems.remove((Integer.valueOf(position)));
                        }
                    }
                });

                mBuilder.setCancelable(false);
                mBuilder.setPositiveButton(R.string.ok_label, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int which) {
                        String item = "";
                        for (int i = 0; i < mProfesionItems.size(); i++) {
                            item = item + listItems[mProfesionItems.get(i)];
                            if (i != mProfesionItems.size() - 1) {
                                item = item + ", ";

                            }
                        }

                        profTextView.setText(item);                        
                        dataReference.child("perfiles").child(user_id).child("profesion").setValue(profTextView);
                    }
                });
AlertDialog mDialog = mBuilder.create();
            mDialog.show();
        }

    });
    
asked by Jonatan Paez 22.10.2018 в 17:51
source

1 answer

1

Ready, I got what I wanted, thank you very much, I do not know how to resolve this. I also share in case at some point in life someone in years if you follow this, maybe it will serve you. Greetings.

mBuilder.setPositiveButton(R.string.ok_label, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int which) {

                    String item = "";
                    for (int i = 0; i < mProfesionItems.size(); i++) {
                        String guardarItem = listItems[mProfesionItems.get(i)];
                        item = item + listItems[mProfesionItems.get(i)];
                        if (i != mProfesionItems.size() - 1) {
                            item = item + ", ";
                        }
                        dataReference.child("profesiones").child(guardarItem).setValue(user_id);
                    }

                     profTextView.setText(item);

                    String prof= profTextView.getText().toString();
                    dataReference.child("perfiles").child(user_id).child("profesion").setValue(prof);
                }
            });
    
answered by 23.10.2018 / 01:03
source