2014-04-01 48 views
0

我的代码:HashMap的ArrayList中显示相同的值在AutoCompleteTextView建议两次

// Reading all contacts from database 
    List<BNICorporateBean> contacts = db.getAllInfo(); 
    // Each row in the list stores country name, currency and email 
    ArrayList<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>(); 
     for (BNICorporateBean cn : contacts) 
     { 
      if(!memId.trim().equalsIgnoreCase(cn.getBNIMemID().trim())) 
      { 
       HashMap<String, String> hm = new HashMap<String,String>(); 
       hm.put("name", cn.getMemName()); 
       hm.put("email", cn.getMemEmail()); 
       hm.put("mem_id", cn.getBNIMemID()); 
       Log.d("Result", cn._MemName+"\n"+cn._MemEmail+"\n"+cn._BNIMemID);        
       aList.add(hm); 
      } 
      memId= cn.getBNIMemID(); 
      //infoArry.add(cn); 

     } 

    // Keys used in Hashmap 
    //String[] from = { "name","email"}; 
    // Ids of views in listview_layout 
    //int[] to = { R.id.mem_name,R.id.mem_email}; 

    // Instantiating an adapter to store each items 
    // R.layout.listview_layout defines the layout of each item 
    SimpleAdapter adapter = new SimpleAdapter(LoginActivity.this, aList, R.layout.list_member, new String[] { "name","email"}, 
      new int[]{ R.id.mem_name,R.id.mem_email}); 
    /** Setting the adapter to the listView */ 
    autoComplete.setAdapter(adapter);   

从数据库中提取价值,我的日志文本显示,它返回一个值,但不知道为什么会出现相同值的两倍在列表建议中。注意:对于一些值,它会显示一次。

我还打印我的列表,并给出了完美的结果没有重复的值

for(int k=0;k<aList.size();k++) 
{ 
System.out.println(""+aList.get(k)); 
} 
+0

你检查的ArrayList?打印并检查ArrayList ... – Yuvaraja

+0

@Yuvaraja请检查我的编辑。打印列表给出完美的值,不会有重复 –

回答

2

使用it.This可以帮助你

do{ 
    HashMap<String, String> hm = new HashMap<String,String>(); 
    hm.put("name", cn.getMemName()); 
    hm.put("email", cn.getMemEmail()); 
    hm.put("mem_id", cn.getBNIMemID()); 
    Log.d("Result", cn._MemName+"\n"+cn._MemEmail+" \n"+cn._BNIMemID);        
    aList.add(hm); 
    memId= cn.getBNIMemID(); 
}while(!memId.trim().equalsIgnoreCase(cn.getBNIMemID().trim())); 
+0

没用...... –

相关问题