展会信息港展会大全

将 Spanned 放到 ListView.setAdapter 的方法
来源:互联网   发布日期:2015-11-26 09:48:10   浏览:2081次  

导读:需要重载一个 BaseAdapter 类1.[代码][Java]代码public static class SpannedAdapter extends BaseAdapter { private LayoutInflater mInflater; private ArrayListSpanned mArticleList; publ......

需要重载一个 BaseAdapter 类

1. [代码][Java]代码

public 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;

}

}

2. [代码]使用方法

list.setAdapter(new SpannedAdapter(this, articleItemsHelper));

赞助本站

人工智能实验室

相关热词: Spanned ListView setAdapter

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港