我想将两个arraylist添加到一个中,以便将其设置为一个并显示..,在一个arraylist中,我从联系人列表中检索名称,在其他情况下,即时恢复数字。通过组合这两个我希望将它们显示在自动完成文本视图。 的 MainActivity
Cursor phones = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
+ " ASC");
while (phones.moveToNext()) {
phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
name = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
System.out.println(phoneNumber);
name1.add(name);
phno1.add(phoneNumber);
// meMap.put("name1","phno1");
// mPeopleList.add(name);
// mPeopleList.add(phoneNumber);
ArrayList<HashMap<String, String>> inviteList = new ArrayList<HashMap<String, String>>();
for(int i=0;i < name1.size();i++)
{
HashMap map = new HashMap<String, String>();
map.put(name1.get(i).toString());
map.put("emailID", inviteListRespone.get(i).getEmail());
inviteList.add(map);
}
}
searchText = (AutoCompleteTextView) findViewById(R.id.autocomplete);
//String[] from={ Phone.DISPLAY_NAME, phoneNumber};
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,name1);
lv = (ListView) findViewById(R.id.lv);
ma = new MyAdapter();
searchText.setThreshold(1);
searchText.setAdapter(adapter);
答案 0 :(得分:0)
为了澄清一下,您正在从数据库中检索电话号码和姓名,并且您想要在列表中显示它们吗?
如果你想使用我不推荐的数组适配器,你必须将你的信息合并到一个字符串中,因为你使用的布局只包含一个textview。
您要合并的代码应该类似于
for (int i = 0; i < name1.size(); i++) {
String name = name1.get(i);
name += " " + phno1.get(i);
}
然后只将名称列表传递给适配器。
但您可以将代码更改为
while (phones.moveToNext()) {
phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
name = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
System.out.println(phoneNumber);
name1.add(name + " " + phoneNumber); // changed this
...
这样你就不必再次遍历列表了。