Issue
In MySql database i have a product table with more columns :
catergories, model, color, size, price .
In Android app on SplashActivity
i get te data from products table save it in a constant ArrayList
and populate the RecyclerView
with all product list.
How can i get distinct categories, distinct model, distinct color from this arraylist? I want to use those in dropboxes for filter the product list.
This is how i get the data from Mysql table and save it in Constant.allProducts
,
call.enqueue(new Callback<ProductMain>() {
@Override
public void onResponse(Call<ProductMain> call, Response<ProductMain> response) {
ProductMain main=response.body();
Constants.toateProdusele.clear();
Constants.toateProdusele.addAll(main.getProduse())
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this,HomePageActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
finish();
}
},1500);
}
@Override
public void onFailure(Call<ProductMain> call, Throwable t) {
Toast.makeText(SplashActivity.this,""+t,Toast.LENGTH_LONG).show();
}
});
//and i populate the recyclerview
arrayList = new ArrayList<>();
arrayList.addAll(Constants.toateProdusele);
adapter= new ProduseAdapter(HomePageActivity.this, arrayList, ProductDetailActivity.class) ;
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
Solution
Welcome to the stackoverflow.
Instead to save it in an ArrayList<>
use a HashSet<>
that will only save unique values,
If the list contains objects of classes defined in your code you will have to overwrite the equals()
method in that class in order to distinguish which objects are different from each other and also the hashcode()
method
Answered By - from56
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.