解析 json 文件后创建列表适配器。内容还可以,但列表中只有相同的元素(最后一个元素)。有什么问题?
主要活动:
CatalogAdapter catAdapter;
catAdapter = new CatalogAdapter(this, events);
setListAdapter(catAdapter);
目录适配器:
CatalogAdapter(Context context, ArrayList<ListData> _events) {
cont = context;
events = _events;
lInflater = (LayoutInflater) cont.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return events.size();
}
public ListData getItem(int position) {
return events.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.inetlist, parent, false);
}
ListData p = getItem(position);
((TextView) view.findViewById(R.id.title)).setText(p.title);
((TextView) view.findViewById(R.id.decription)).setText("Описание: \n"+p.description);
return view;
}