本文实例为大家分享了XListView实现刷新加载的具体代码,供大家参考,具体内容如下
MainActivity.java
保护空白> & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比; & lt; android.support.constraint。ConstraintLayout xmlns: android=" http://schemas.android.com/apk/res/android " xmlns:应用=" http://schemas.android.com/apk/res-auto " xmlns:工具=" http://schemas.android.com/tools " android: layout_width=" match_parent " android: layout_height=" match_parent " 工具:上下文=?ui.MainActivity”比; LinearLayout & lt; android: layout_width=" match_parent " android: layout_height=" match_parent " android:取向=按怪薄? 比; & lt; android.support.v4.view.ViewPager android: id=癅 + id/: viewpage” android: layout_width=" match_parent " android: layout_height=" 0 dp” android: layout_weight=" 9 " 比; & lt;/android.support.v4.view.ViewPager> & lt; RadioGroup android: id=癅 + id/组” android: layout_width=" match_parent " android: layout_height=" wrap_content " android: layout_weight=" 1 " 面向android:="水平" 比; & lt; RadioButton android: id=癅 + id/r1” android: layout_width=" wrap_content " android: layout_height=" match_parent " android:按钮=" @null " android:重力="中心" android: layout_weight=" 1 " android:文本=" Afrag "/比; & lt; RadioButton android: id=癅 + id/r2” android: layout_width=" wrap_content " android: layout_height=" match_parent " android:按钮=" @null " android:重力="中心" android: layout_weight=" 1 " android:文本=" Bfrag "/比; & lt; RadioButton android: id=癅 + id/r3” android: layout_width=" wrap_content " android: layout_height=" match_parent " android:按钮=" @null " android:重力="中心" android: layout_weight=" 1 " android:文本=" Cfrag "/比; & lt; RadioButton android: id=癅 + id/r4” android: layout_width=" wrap_content " android: layout_height=" match_parent " android:按钮=" @null " android:重力="中心" android: layout_weight=" 1 " android:文本=" Dfrag "/比; & lt;/RadioGroup> & lt;/LinearLayout> & lt;/android.support.constraint.ConstraintLayout> >之前Afragment.java
公开课Afragment延伸片段{ 私人int页面=1; 私人XListView列表视图; 私人MyBaseAdapter适配器; ResponseBean ResponseBean; @Nullable @Override 公共ViewGET”); urlConnection.setReadTimeout (5000); urlConnection.setConnectTimeout (5000); int responseCode=urlConnection.getResponseCode (); 如果(responseCode==200) { 字符串的结果=String2相等(urlConnection.getInputStream ()); responseBean=new Gson () .fromJson(因此,ResponseBean.class); 其他}{ } 返回responseBean==null & # 63;零:responseBean.getResult () .getData (); }捕捉(MalformedURLException e) { e.printStackTrace (); }捕捉(IOException e) { e.printStackTrace (); } 返回null; } @Override 保护空白> 公开课MyBaseAdapter延伸BaseAdapter { 私人List数据; 私人LayoutInflater LayoutInflater; 公共MyBaseAdapter (LayoutInflater LayoutInflater) { 这一点。layoutInflater=layoutInflater; ,数据=new ArrayList<的在(); } 公共空间setDatas (List 数据){ datas.clear (); 如果(数据!=null) { datas.addAll(数据); } notifyDataSetChanged (); } 公共空间adddata (List dataItems) { 如果(dataItems !=null) { datas.addAll (dataItems); notifyDataSetChanged (); } } 公众最终int VIEW_TYPE_COUNT=2; 公众最终int IMAGE_TEXT_TYPE=0; 公众最终int TEXT_TYPE=1; @Override 公共int getItemViewType (int位置){ 如果(位置% 2==0){ 返回IMAGE_TEXT_TYPE; 其他}{ 返回TEXT_TYPE; } } @Override 公共int getViewTypeCount () { 返回VIEW_TYPE_COUNT; } @Override 公共int getCount () { 返回datas.size (); } @Override 公共对象getItem (int i) { 返回datas.get(我); } @Override 公共长getItemId (int i) { 返回我; } @Override 观点看来,公众视线getView (int我ViewGroup ViewGroup) { 如果(getItemViewType (i)==IMAGE_TEXT_TYPE) { ViewHolder ViewHolder=零; 如果(查看==null) { 视图=layoutInflater.inflate(出来。项,viewGroup、假); viewHolder=new viewHolder(查看); 其他}{ viewHolder=(viewHolder) view.getTag (); } viewHolder.bindData ((DataItem) getItem(我)); 其他}{ ViewHolder2 ViewHolder2; 如果(查看==null) { 视图=layoutInflater.inflate(出来。viewGroup item_text,假); viewHolder2=new viewHolder2 (); viewHolder2。textView=view.findViewById (R.id.text); view.setTag (viewHolder2); 其他}{ viewHolder2=(viewHolder2) view.getTag (); } viewHolder2.textView.setText (datas.get (i) .getTitle ()); } 返回视图; } 公开课ViewHolder { 私人ImageView图标; 私人TextView标题; 私人TextView日期; 公共ViewHolder(查看视图){ 图标=view.findViewById (R.id.icon); title=view.findViewById (R.id.title); 日期=view.findViewById (R.id.date); view.setTag(这个); } 公共空间bindData (DataItem项){ title.setText (item.getTitle ()); date.setText (item.getId ()); ImageLoader.getInstance () .displayImage (item.getFirst(),图标 ImageloaderConfigs.getDefult (icon.getContext ())); } } 公开课ViewHolder2 { TextView TextView; } } XListView实现多条目网络数据刷新加载网络加载图片