gpt4 book ai didi

java - HashMap ArrayList 在 AutoCompleteTextView 建议中显示相同的值两次

转载 作者:行者123 更新时间:2023-12-02 05:59:35 24 4
gpt4 key购买 nike

我的代码:

// 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));
}

最佳答案

使用它。这可能对你有帮助

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()));

关于java - HashMap ArrayList 在 AutoCompleteTextView 建议中显示相同的值两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22783980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com