ListView使用自定义adapter后只显示一条数据,使用simpleadapter数据就能全部显示出来 public final class ViewHolder { public TextView shopname; public ImageView telephone; public TextView noticetitle; public TextView noticedate; public TextView content; } public class MyAdapter extends BaseAdapter { private LayoutInflater mInflater; Context c; List<Map<String, Object>> d; public MyAdapter(Context context,List<Map<String, Object>> data) { c = context; d=data; this.mInflater = LayoutInflater.from(context); } @Override public int getCount() { return d.size(); } @Override public Object getItem(int arg0) { return d.get(arg0); } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return arg0; } @Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.noticelistview, null); holder.shopname = (TextView) convertView.findViewById(R.id.txt_shopname); holder.telephone= (ImageView) convertView.findViewById(R.id.telephone); holder.noticetitle = (TextView) convertView.findViewById(R.id.txt_noticetitle); holder.noticedate = (TextView) convertView.findViewById(R.id.txt_noticedate); holder.content = (TextView) convertView.findViewById(R.id.txt_content); holder.telephone.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String phone=((ImageView)v).getTag().toString(); }}); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); holder.shopname.setText(d.get(position).get("shop_name").toString()); holder.telephone.setTag(d.get(position).get("shop_phone")); holder.noticetitle.setText(d.get(position).get("notice_title").toString()); holder.noticedate.setText(d.get(position).get("createtime").toString()); holder.content.setText(d.get(position).get("notice_note").toString()); } return convertView; } } |
|
100分 |
try
@Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.noticelistview, null); holder.shopname = (TextView) convertView.findViewById(R.id.txt_shopname); holder.telephone= (ImageView) convertView.findViewById(R.id.telephone); holder.noticetitle = (TextView) convertView.findViewById(R.id.txt_noticetitle); holder.noticedate = (TextView) convertView.findViewById(R.id.txt_noticedate); holder.content = (TextView) convertView.findViewById(R.id.txt_content); holder.telephone.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String phone=((ImageView)v).getTag().toString(); }}); convertView.setTag(holder); } else holder = (ViewHolder) convertView.getTag(); holder.shopname.setText(d.get(position).get("shop_name").toString()); holder.telephone.setTag(d.get(position).get("shop_phone")); holder.noticetitle.setText(d.get(position).get("notice_title").toString()); holder.noticedate.setText(d.get(position).get("createtime").toString()); holder.content.setText(d.get(position).get("notice_note").toString()); return convertView; } |
解决了 非常感谢
|
|
你好,请问你是怎么解决的了? try吗?
|