删除重复从ListView的机器人 [英] Removing Duplicates From ListView android
本文介绍了删除重复从ListView的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我张贴我的code,我无法从列表视图中删除重复值?
是否有人可以帮助我吗?提前致谢!
我贴我的code在这里,我已经使用 BaseAdapter
。
@覆盖
公共无效onCompleted(最终名单,其中,值得推荐>的结果){
android.util.Log.w(suggestionview>>>>>中,建议+ result.size());
((活动)mContext).runOnUiThread(新的Runnable(){
公共无效的run(){
迭代器<值得推荐的> ITR = result.iterator();
而(itr.hasNext()){
值得推荐的元素= itr.next();
suggestions.add(元);
android.util.Log.w(suggestionview,添加元素::>+ suggestions.add(元));
}
suggestionListView.setAdapter(新Suggestiondapter(mContext));
android.util.Log.w(suggestionview,建议适配器价值观::>+ suggestionListView);
}
});
以及code中的第二个
公共类Suggestiondapter扩展了BaseAdapter {
//私人LayoutInflater mInflater = NULL;
私人语境mContext;
公共Suggestiondapter(上下文mContext){
this.mContext = mContext;
android.util.Log.w(建议适配器,vlues都正在添加......);
}
@覆盖
公众诠释getCount将(){
android.util.Log.w(suugestion适配器,suggstion尺寸::>中+ suggestions.size());
返回suggestions.size();
}
@覆盖
公共对象的getItem(INT位置){
返回的位置;
}
@覆盖
众长getItemId(INT位置){
返回的位置;
}
@覆盖
公共查看getView(INT位置,查看convertView,ViewGroup中父){
值得推荐推荐= suggestions.get(位置);
如果(convertView == NULL){
android.util.Log.w(convertView,adaptervalues ........ ::>中+ recommendable.Program);
android.util.Log.w(系列conveter,计划值系列::>+ recommendable.Series);
convertView =新HeaderView(mContext,recommendable.Program,recommendable.Series,SuggestionView.class);
}其他{
Toast.makeText(mContext,为helloView,Toast.LENGTH_SHORT);
}
返回convertView;
}
};
解决方案
如果您不希望允许重复到您的收藏对象,然后使用Set对象,现在将允许重复的值。
设置建议=新的HashSet();
也可以添加您的列表对象这个对象,现在将增加重复值
ArrayList的人=新的ArrayList();
//添加元素人,包括重复
HashSet的HS =新的HashSet();
hs.addAll(人);
al.clear();
al.addAll(HS);
更新你的情况:
使用您的建议对象,而不是上面的人对象只是它。
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){
android.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;
}
};
解决方案
If you don't want to allow duplicate into collection of your object then use the Set object it will now allow the duplicate value.
Set suggestion = new HashSet();
or you can add your list object to this object it will now add duplicate value
ArrayList al = new ArrayList();
// add elements to al, including duplicates
HashSet hs = new HashSet();
hs.addAll(al);
al.clear();
al.addAll(hs);
updated for your case:
use your suggestion object instead of the above al object just it.
这篇关于删除重复从ListView的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文