ListView只显示一条数据????

Android 码拜 10年前 (2015-04-23) 1475次浏览 0个评论

ListView使用自定义adapter后只显示一条数据,使用simpleadapter数据就能全部显示出来
没有使用Scrollview
求指导?


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


	}

ListView只显示一条数据????
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;
    }
ListView只显示一条数据????
解决了 非常感谢
ListView只显示一条数据????
你好,请问你是怎么解决的了? try吗?

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明ListView只显示一条数据????
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!