Firebase RecycleView с Edittext несколько изменений одновременно - PullRequest
1 голос
/ 09 мая 2020

У меня есть список изображений, заполненный firebase recyclerView и edittext, чтобы оценить их.

Когда я помещаю номер рейтинга в какое-то изображение, он одновременно дублируется в другом изображении. enter image description here

Я видел здесь несколько ответов, но все они не имеют отношения к версии Firebase, пожалуйста, помогите мне:

My

MainActivity activity:
public class CreateNewPollUserActivity extends AppCompatActivity {


    FirebaseAuth mAuth;
    String currentUserID, party_name, party_flag, mandatim;

    private int count;
    private int calc = 0;
    TextView total;
    RecyclerView PartiesList;
    DatabaseReference gameRef = FirebaseDatabase.getInstance().getReference().child("game_list");

    AppCompatButton save_btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_new_poll_user_new);

        mAuth = FirebaseAuth.getInstance();
        currentUserID = mAuth.getCurrentUser().getUid();


        total = (TextView) findViewById(R.id.total);
        save_btn = (AppCompatButton) findViewById(R.id.btn_save);


        //The next code is working on displaying all users posts
        PartiesList = (RecyclerView) findViewById(R.id.parties_list);
        PartiesList.setHasFixedSize(true);
        LinearLayoutManager linearLayoutManager = new 
LinearLayoutManager(CreateNewPollUserActivity.this);
        linearLayoutManager.setReverseLayout(true);
        linearLayoutManager.setStackFromEnd(true);
        PartiesList.setLayoutManager(linearLayoutManager);
        PartiesList.setItemViewCacheSize(20);


        DisplayAllPartiesList();


    }

    private void DisplayAllPartiesList() {
        Query SortPostsInDecendingOrder = gameRef.child(currentUserID).orderByChild("party_img");

        FirebaseRecyclerOptions<PartiesImg> options =
                new FirebaseRecyclerOptions.Builder<PartiesImg>()
                        .setQuery(SortPostsInDecendingOrder, PartiesImg.class)
                        .build();

        FirebaseRecyclerAdapter<PartiesImg, PartiesImgViewHolder> adapter =
                new FirebaseRecyclerAdapter<PartiesImg, PartiesImgViewHolder>
                        (options) {

                    public void onBindViewHolder(@NonNull final PartiesImgViewHolder viewHolder, int 
 position, @NonNull PartiesImg model) {
                        final String flagKey = getRef(position).getKey();
                        final int flagIntKey = position;


                        viewHolder.setParty_image(model.getParty_image());
                        viewHolder.setMandatim(model.getMandatim());

                        viewHolder.mandatim.addTextChangedListener(new TextWatcher() {
                            @Override
                            public void beforeTextChanged(CharSequence charSequence, int i, int i1, 
int i2) {

                            }

                            @Override
                            public void onTextChanged(CharSequence charSequence, int i, int i1, int 
i2) {

                            }

                            @Override
                            public void afterTextChanged(Editable editable) {

                                if(!viewHolder.mandatim.getText().toString().equals("")) {
                                    HashMap partyMap = new HashMap();
                                    partyMap.put("mandatim", 
viewHolder.mandatim.getText().toString());

gameRef.child(currentUserID).child(flagKey).updateChildren(partyMap);
                                }

                            }
                        });

                        total.setText(String.valueOf(calc));


                    }


                    @NonNull
                    @Override
                    public PartiesImgViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int 
viewType) {
                        View view = 
LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.all_parties_img_layout, viewGroup, 
false);
                        PartiesImgViewHolder viewHolder = new PartiesImgViewHolder(view);
                        return viewHolder;
                    }
                };

        PartiesList.setAdapter(adapter);
        adapter.startListening();


    }

    private void closeKeyboard() {
        View view = CreateNewPollUserActivity.this.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) 
CreateNewPollUserActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }

    }
}

Мои группыImgViewHolder класс

public class PartiesImgViewHolder extends RecyclerView.ViewHolder {
View mView;

AppCompatButton btn_delete;
EditText mandatim;

public PartiesImgViewHolder(View itemView) {
    super(itemView);
    mView = itemView;

    btn_delete=(AppCompatButton) mView.findViewById(R.id.btn_delete);
    mandatim=(EditText) mView.findViewById(R.id.mandatim);



}


public void setParty_image(String party_image) {
    ImageView _image = (ImageView) mView.findViewById(R.id._image);
    Picasso.get().load(party_image).into(_image);
}

public void setMandatim(String mandatim) {
    EditText _mandatim = (EditText) mView.findViewById(R.id.mandatim);
    _mandatim.setText(mandatim);
}

}

и all_parties_img_layout. xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:orientation="horizontal"
    android:background="@color/white"
    android:weightSum="3"
    android:layout_margin="2dp">



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="2">
        <ImageView
            android:id="@+id/_image"
            android:layout_width="90dp"
            android:layout_height="45dp"
            android:layout_marginLeft="20dp"
            android:src="@mipmap/ic_loading"
            android:layout_gravity="center"
            />
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="4">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3"
            >
            <EditText
                android:id="@+id/mandatim"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:inputType="number"
                android:layout_gravity="center"
                android:textColor="@color/black"
                />


        </LinearLayout>


    </LinearLayout>
...