简单但有点棘手,如果我有
list.setAdapter(new ArrayAdapter<String>(this,R.layout.double_row, R.id.doubleRow, articleItemsHelper));
如果articleItemsHelper是String,它可以工作,但我想在那里有 HTML 格式,所以当articleItemsHelper是跨类型时,这个(适配器)不起作用。
ArrayList<Spanned> articleItemsHelper = new ArrayList<Spanned>();
解决方案是什么?
编辑:这是解决方案 -自定义适配器
private static class SpannedAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private ArrayList<Spanned> mArticleList;
public SpannedAdapter(Context context, ArrayList<Spanned> articleList) {
mInflater = LayoutInflater.from(context);
mArticleList = articleList;
}
public int getCount() {
return mArticleList.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.single_row, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.singleRow);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(mArticleList.get(position));
return convertView;
}
static class ViewHolder {
TextView text;
}
}
然后定期打电话
list.setAdapter(new SpannedAdapter(this, articleItemsHelper));
在哪里
articleItemsHelper
是
ArrayList<Spanned>