//主布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.a1.day9_xiala.MainActivity"> <com.handmark.pulltorefresh.library.PullToRefreshScrollView android:id="@+id/pull_to_refresh_scrollview" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.example.a1.day9_xiala.MyListview android:id="@+id/lis_view" android:layout_width="match_parent" android:layout_height="wrap_content"></com.example.a1.day9_xiala.MyListview> </com.handmark.pulltorefr
//适配器
public class ListAdapter extends BaseAdapter{ private Context context; private List<NewsBean.ResultBean.DataBean>list; public ListAdapter(Context context, List<NewsBean.ResultBean.DataBean> list) { this.context = context; this.list = list; } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView==null){ convertView=View.inflate(context,R.layout.item_layout,null); holder=new ViewHolder(); holder.textView=convertView.findViewById(R.id.text_title); convertView.setTag(holder); }else{ holder= (ViewHolder) convertView.getTag(); } holder.textView.setText(list.get(position).getTitle()); return convertView; } class ViewHolder{ TextView textView; } }
//Activty
文章来源: 上拉刷新