我为即将推出的应用程序提供了表情符号的自定义实现。我希望用户选择一个表情符号,然后将其插入编辑文本中,他可以根据自己的喜好添加更多文本。当用户单击按钮时,我想将edittext内容添加到ArrayList,该ArrayList将传递给适配器以在textview listview项中显示。 最初这是我的实施。
private ArrayList<Spanned> chats;
private EditText content;
-------
Spanned sp = content.getText();
chats.add(String.valueOf(sp));
content.setText("");
mAdapter.notifyDataSetChanged();
然后在适配器类中,这是我显示内容的方式。
private ArrayList<Spanned> comments;
-------
public View getView(final int position, View convertView, ViewGroup parent){
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.chatlist_item, null);
}
final Spanned item = comments.get(position);
TextView fans_image = (TextView) v.findViewById(R.id.item_text);
fans_image.setText(item);
-------
}
上述实施工作正常。但现在我希望ArrayList具有String项而不是Spanned项。 我正在尝试以下实现。 在我的活动中:
private ArrayList<String> chats;
------
Spanned sp = content.getText();
chats.add(String.valueOf(sp));
content.setText("");
mAdapter.notifyDataSetChanged();
在适配器中:
private ArrayList<String> comments;
--------
public View getView(final int position, View convertView, ViewGroup parent){
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.chatlist_item, null);
}
final Spanned item = Html.fromHtml(comments.get(position));
TextView fans_image = (TextView) v.findViewById(R.id.item_text);
fans_image.setText(item);
return v;
}
这不起作用。相反,文本显示正确,但表情符号drawable被替换为几乎类似于:obj:
的文本。如何在文本旁边显示drawable?