Removing Duplicates From ListView android
I am posting my code, I am unable to remove the duplicate values from the listview?
Can someone please help me? Thanks in advance!
I am pasting my code here and I have used BaseAdapter
.
@Override
public void onCompleted(final List<Recommendable> result) {
android.util.Log.w("suggestionview>>>>>", "suggestion"+ result.size());
((Activity) mContext).runOnUiThread(new Runnable() {
public void run() {
Iterator<Recommendable> itr = result.iterator();
while (itr.hasNext()) {
Recommendable element = itr.next();
suggestions.add(element);
android.util.Log.w("suggestionview", "Adding elements::>"+suggestions.add(element));
}
suggestionListView.setAdapter(new Suggestiondapter(mContext));
android.util.Log.w("suggestionview","suggestion adapter Values::>"+suggestionListView);
}
});
And the second of the code
public class Suggestiondapter extends BaseAdapter {
// private LayoutInflater mInflater = null;
private Context mContext;
public Suggestiondapter(Context mContext) {
this.mContext=mContext;
android.util.Log.w("Suggestion Adapter","vlues are comming.....");
}
@Override
public int getCount() {
android.util.Log.w("suugestion adapter","suggstion size::>"+suggestions.size());
return suggestions.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Recommendable recommendable = suggestions.get(position);
if(convertView==null){
andr开发者_如何学Gooid.util.Log.w("convertView", "adaptervalues........::>"+ recommendable.Program);
android.util.Log.w("series conveter", "program series values::>"+recommendable.Series);
convertView = new HeaderView(mContext, recommendable.Program,recommendable.Series, SuggestionView.class);
}else{
Toast.makeText(mContext, "HelloView", Toast.LENGTH_SHORT);
}
return convertView;
}
};
You could use that code:
private static HashSet<String> hs = new HashSet<String>();
private static ArrayList<String> list= new ArrayList<String>();
for(int i=0; i<list.size(); i++){
hs.add(list.get(i));
}
list.clear();
list.addAll(hs);
精彩评论