Reputation:
In my application I want use this library : https://github.com/fiskurgit/ChipCloud
I can added my lists from server into this chip clouds and for this I write below code :
List<String> cloudChipList = new ArrayList<>();
private String[] mostlyMatchedKeywordsStrings;
mostlyMatchedKeywordsStrings = searchResponse.getData().getMostlyMatchedKeywordsText();
for (String str : mostlyMatchedKeywordsStrings) {
cloudChipList.clear();
cloudChipList.add(str);
if (cloudChipList.size() > 0) {
fullSearchMini_didYouMeanLay.setVisibility(View.VISIBLE);
fullSearchMini_chipCloud.addChip(str);
}
}
In my code show all of list's data, but I want just show 5 data no all of data!
How can I change my above code for show just 5 item ?
Upvotes: 1
Views: 58
Reputation: 1153
You can limit data as much as you would like to limit from server side. You should use Criteria
for that. If you use session, then this sample code would help:
Criteria criteria = session.createCriteria(YourClassName.class);
criteria.setMaxResults(5);
if (criteria.list().size() > 0) {
yourListName = (List<YourClassName>) criteria.list();
}
This code will limit the number of items sent from the server to 5
even if the list has n
number of items.
Upvotes: 0
Reputation: 491
you can simply do like this using counter,if count is above 5 it does not add to the list cloudChipList.
List<String> cloudChipList = new ArrayList<>();
private String[] mostlyMatchedKeywordsStrings;
int count=0;
mostlyMatchedKeywordsStrings = searchResponse.getData().getMostlyMatchedKeywordsText();
for (String str : mostlyMatchedKeywordsStrings) {
cloudChipList.clear();
if(count<5){
cloudChipList.add(str);}
if (cloudChipList.size() > 0) {
fullSearchMini_didYouMeanLay.setVisibility(View.VISIBLE);
fullSearchMini_chipCloud.addChip(str);
}
count++;
}
Upvotes: 1