我的目标
在发送电子邮件时,像gmail一样创建联系人选择器(左侧是圆形图像)。我已经做了一些研究,发现了EditText云和Chip Cloud,但它们不支持自定义布局中的图像,并且适配器只接受List<String>
。有人对如何实现它或使用库来实现这一点有正确的想法。
提前致谢。
答案 0 :(得分:2)
我建议您使用TokenAutoComplete
public class ContactsCompletionView extends TokenCompleteTextView<Person> {
public ContactsCompletionView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View getViewForObject(Person person) {
LayoutInflater l = (LayoutInflater) getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
TextView view = (TextView) l.inflate(R.layout.contact_token, (ViewGroup) getParent(), false);
view.setText(person.getEmail());
return view;
}
@Override
protected Person defaultObject(String completionText) {
//Stupid simple example of guessing if we have an email or not
int index = completionText.indexOf('@');
if (index == -1) {
return new Person(completionText, completionText.replace(" ", "") + "@example.com");
} else {
return new Person(completionText.substring(0, index), completionText);
}
}
}
<强>输出:强>