导入xlistview包,这里我就不展示了
子条目布局
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text" android:layout_marginTop="50px" />
首先,写好我们的适配器
public class myadapter extends BaseAdapter { Context context; ArrayList<Goods> list; public myadapter(Context context, ArrayList<Goods> list) { this.context = context; this.list = list; } @Override public int getCount() { return list.size(); } @Override public Goods getItem(int i) { return list.get(i); } @Override public long getItemId(int i) { return i; } @Override public View getView(int i, View view, ViewGroup viewGroup) { ViewHoler holer; if (view==null){ view= LayoutInflater.from(context).inflate(R.layout.itemmobel,viewGroup,false); holer=new ViewHoler(); holer.img=(ImageView) view.findViewById(R.id.img); holer.text=(TextView)view.findViewById(R.id.text); view.setTag(holer); }else { holer=(ViewHoler)view.getTag(); } Goods g=getItem(i); holer.text.setText(g.title); holer.img.setImageResource(g.img); return view; } class ViewHoler{ ImageView img; TextView text; } 然后就是我们的数据配置情况mlistview=(XListView)findViewById(R.id.xlistview); mlistview.setPullLoadEnable(true); list=new ArrayList<Goods>(); list.add(new Goods("我的第一个个产品",R.mipmap.a11)); list.add(new Goods("我的第二个个产品",R.mipmap.a12)); list.add(new Goods("我的第三个个产品",R.mipmap.a13)); list.add(new Goods("我的第四个个产品",R.mipmap.a14)); list.add(new Goods("我的第五个个产品",R.mipmap.a15)); myadapter = new myadapter(MainActivity.this, list); mlistview.setAdapter(myadapter); mlistview.setXListViewListener(this); } @Override public void onRefresh(){ handler.postDelayed(new Runnable() { @Override public void run() { //获取当前时间 Date curDate = new Date(System.currentTimeMillis()); //格式化 SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日HH:mm:ss"); String time = formatter.format(curDate); mlistview.setRefreshTime(time); myadapter = new myadapter(MainActivity.this, list); mlistview.setAdapter(myadapter); onLoad(); } },2000); } @Override public void onLoadMore() { handler.postDelayed(new Runnable() { @Override public void run() { list.add(new Goods("我的第一个个产品",R.mipmap.a11)); list.add(new Goods("我的第二个个产品",R.mipmap.a12)); list.add(new Goods("我的第三个个产品",R.mipmap.a13)); list.add(new Goods("我的第四个个产品",R.mipmap.a14)); list.add(new Goods("我的第五个个产品",R.mipmap.a15)); myadapter.notifyDataSetChanged(); onLoad(); } },2000); } public void onLoad(){ mlistview.stopLoadMore(); mlistview.stopRefresh(); mlistview.setRefreshTime("刚刚"); }