Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – AutoCompleteView sending data to RecycleView

Posted on November 11, 2022 By

Solution 1 :

In fact, to solve my problem, I needed to see two things.

The first refers to removing the RecycleViewerListAdapter from within the onItemClick, so that it does not replace what is on the screen.

    ac_tv_Product.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            addItemToRecycle(position);
        }
    });

    recycleViewerListAdapter = new RecycleViewerListAdapter(teste);
    rvShoppingList.setAdapter(recycleViewerListAdapter);
}

The second is directly in the Recycle Row xml, as it needs to be as a wrap parent for more than one to appear in the list.

android:layout_width="match_parent"
android_layout_height="wrap_content"

 

Problem :

I’m working on autocompleteview, which brings up the surges according to what was registered in Firebase. I want that when typing and showing the options I can click on the suggestion that appears and send it to the recycleViewer at the bottom.

prototype

However my problem is in the recording of the data inside the recycle. When doing the second search, instead of joining the previous one, the new one replaces the old one.

public class NewListActivity extends AppCompatActivity {

private FirebaseFirestore db = FirebaseFirestore.getInstance();

private CollectionReference docRef =
        db.collection("data")
                .document(FirebaseAuth.getInstance().getCurrentUser().getUid())
                .collection("product");

private AutoCompleteTextView ac_tv_Product;
private AutoCompleteProductAdapter autoCompleteProductAdapter;

private RecyclerView rvShoppingList;
private RecycleViewerListAdapter recycleViewerListAdapter;

private List<ProductItem> productItemsList = new ArrayList<>();

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

    getDataFromFire();

    ac_tv_Product = findViewById(R.id.ac_tv_Product);
    rvShoppingList = findViewById(R.id.rvShoppingList);
    rvShoppingList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));

    autoCompleteProductAdapter = new AutoCompleteProductAdapter(this, productItemsList);
    ac_tv_Product.setAdapter(autoCompleteProductAdapter);

    recycleViewerListAdapter = new RecycleViewerListAdapter(productItemsList);

    ac_tv_Product.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            addItemToRecycle(position);
        }
    });
}

private void addItemToRecycle(int position) {
    rvShoppingList.setAdapter(recycleViewerListAdapter);
   Log.e("ItemCount", String.valueOf(recycleViewerListAdapter.getItemCount()));

}

private void getDataFromFire() {
    docRef.get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (isFinishing() || isDestroyed()) return;
                    if (task.isSuccessful()) {
                        for (QueryDocumentSnapshot document : task.getResult()) {
                            Log.d("Deu certo", document.getId() + " => " + document.getData());
                            String name = document.getString("name");
                            String local = document.getString("location");

                            productItemsList.add(new ProductItem(name, local));
                        }
                    } else {
                        Log.d("deu errado", "Error getting documents: ", task.getException());
                    }
                }
            });
}

RecyclerView Adapter

public class RecycleViewerListAdapter extends RecyclerView.Adapter<RecycleViewerListAdapter.ViewHolder> {

List<ProductItem> items;

public RecycleViewerListAdapter(List<ProductItem> items) {
    this.items = items;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.activity_list_recycle, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    holder.tvRecycleName.setText(items.get(position).getProductName());
}

@Override
public int getItemCount() {
    return items.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {

    private TextView tvRecycleName, tvRecycleValue, tvRecycleLocal;


    public ViewHolder(@NonNull View itemView) {
        super(itemView);

        tvRecycleName = itemView.findViewById(R.id.tvRecycleName);
        tvRecycleValue = itemView.findViewById(R.id.tvRecycleValue);
        tvRecycleLocal = itemView.findViewById(R.id.tvRecycleLocal);

    }
}

}

Comments

Comment posted by resource

Since it’s Java and Firestore, most likely this

READ  [FIXED] java - Lists are not showing in RecyclerView, whenever searching on Search Filter in Android Kotiln
Powered by Inline Related Posts

Android Tags:android, android-recyclerview, autocompletetextview, google-cloud-firestore

Post navigation

Previous Post: [FIXED] java – App crash after uploaded to play store , working correctly when installed from android studio
Next Post: What is the 21 day fitness challenge?

Related Posts

[FIXED] java – Android, change Bitmap aspect ratio programmatically Android
[FIXED] android – Programmatically test if device fingerprint works correctly Android
[FIXED] android – How can I change Edit Text´s selection color? Android
[FIXED] Android Studio Debugger not showing step button Android
[FIXED] android – Flutter permissions handler doesn’t allow to run lines below Android
[FIXED] java – how to delete the auto generated item from push method from Firebase Real-time database Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme