请问ArrayList<Fragment>这个加入的fragment是有次序问题吗?

图片说明

package com.bn.article;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.bn.article.GuanZhuFragment;
import com.bn.article.TuiJianFragment;
import com.bn.myutil.LoadingDiolog;
import com.bn.zol.R;
import com.bn.zolandroid.MainActivity;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment
        implements ViewPager.OnPageChangeListener, View.OnClickListener {

    View view;
    MainActivity mainActivity;
    //选项卡中的按钮
    private Button btn_first;
    private LinearLayout title;
    private Button btn_second;
    //作为指示标签的按钮
    private ImageView cursor;
    //标志指示标签的横坐标
    float cursorX=0;
    //所有标题按钮的数组
    private Button[] btnArgs;
    //fragment的集合,对应每个子页面
    MyFragmentPagerAdapter adapter;
    private ViewPager myviewpager;
    //加载中相关
    private LoadingDiolog dialog;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message mes){
            switch (mes.what) {
                case 0:
                    initView();
                    dialog.dismiss();
                    break;
                default:break;
            }
        }
    };

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        view=inflater.inflate(R.layout.home,container,false);
        dialog= LoadingDiolog.show(MainActivity.activity,"加载中......",true,null);
        new Thread(new Runnable() { //获取内容
            @Override
            public void run() {
                GethomeInfoThread gethomeInfoThread=new GethomeInfoThread();
                gethomeInfoThread.run();
            }
        }).start();
        return view;
    }

    private void initView(){
        myviewpager=(ViewPager)view.findViewById(R.id.myviewpager);
        title =(LinearLayout) view.findViewById(R.id.home_title);
        btn_first=(Button)view.findViewById(R.id.title1);
        btn_second=(Button)view.findViewById(R.id.title2);
        btnArgs=new Button[]{btn_first,btn_second};
        cursor=(ImageView)view.findViewById(R.id.biaoqian);
        cursor.setBackgroundColor(getResources().getColor(R.color.black));
        cursor.setBackground(getResources().getDrawable(R.drawable.biaoqian_bg));
        btn_first.post(new Runnable() {
            @Override
            public void run() {
                LinearLayout.LayoutParams lp=(LinearLayout.LayoutParams)cursor.getLayoutParams();
                lp.width=btn_first.getWidth();
                cursor.setLayoutParams(lp);
                cursor.setX(title.getLeft());
            }
        });
        btn_first.setOnClickListener(this);
        btn_second.setOnClickListener(this);
        resetButtonColor();
        btn_first.setTextColor(getResources().getColor(R.color.black));
        mainActivity=(MainActivity)getActivity();
        ArrayList<Fragment> fragments=new ArrayList<>();
        fragments.add(new TuiJianFragment());
        fragments.add(new GuanZhuFragment());
        adapter=new MyFragmentPagerAdapter(this.getFragmentManager(),fragments);
        myviewpager.setAdapter(adapter);
        myviewpager.setOnPageChangeListener(this);
    }

    private void resetButtonColor()
    {
        btn_first.setTextColor(getResources().getColor(R.color.homeone));
        btn_second.setTextColor(getResources().getColor(R.color.homeone));
    }

    @Override
    public void onPageSelected(int position){
        //每次滑动首先重置所有按钮的颜色
        resetButtonColor();
        //将滑动到的当前按钮颜色设置为绿色
        btnArgs[position].setTextColor(getResources().getColor(R.color.black));
        cursorAnim(position);
    }
    @Override
    public void onPageScrolled(int position,float positionOffset,int positionOffsetPixels){

    }
    @Override
    public void onPageScrollStateChanged(int state){}

    @Override
    public void onClick(View view){
        switch (view.getId()){
            case R.id.title1:
            myviewpager.setCurrentItem(0);
            cursorAnim(0);
            break;
            case R.id.title2:
                myviewpager.setCurrentItem(1);
                cursorAnim(1);
                break;
        }
    }

    //指示器的跳转,传入当前所处的页面的下标
    public void cursorAnim(int curItem)
    {
        cursorX=title.getLeft();
        //再根据当前的curItem来设置指示器的宽度
        LinearLayout.LayoutParams lp=(LinearLayout.LayoutParams)cursor.getLayoutParams();
        lp.width=btnArgs[curItem].getWidth();
        cursor.setLayoutParams(lp);
        //循环获取当前页之前的所有页面的宽度
        for (int i=0;i<curItem;i++){
            cursorX=cursorX+btnArgs[i].getWidth();
        }
        cursor.setX(cursorX);
    }

    public class MyFragmentPagerAdapter extends FragmentPagerAdapter{
        private ArrayList<Fragment> fragments;
        public MyFragmentPagerAdapter(FragmentManager FragmentManager,ArrayList<Fragment> fragments){
            super(FragmentManager);
            this.fragments=fragments;
        }
        @Override
        public Fragment getItem(int position){
            return fragments.get(position);
        }
        @Override
        public int getCount(){
            return fragments.size();
        }
    }


    private class GethomeInfoThread extends  Thread
    {
        @Override
        public void run() {
            super.run();
            Message message=new Message();
            message.what=0;
            handler.sendMessage(message);
            dialog.dismiss();
        }
    }
}

package com.bn.article;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.bn.myutil.MyText;
import com.bn.myview.ListViewScroll;
import com.bn.util.Constant;
import com.bn.util.MyGetBitmap;
import com.bn.util.NetInfoUtil;
import com.bn.util.StrListChange;
import com.bn.zol.R;
import com.bn.zolandroid.MainActivity;

import java.util.ArrayList;
import java.util.List;

public class GuanZhuFragment extends Fragment  {
    LayoutInflater myinflater;
    View view;
    Typeface font;
    private List<String[]> ls;
    private String[][] gzMess;
    private Bitmap[][] gzBitmap;
    byte pic[];
    private ListView listView;
    TextView name;
    MyText myText;
//    private MyListAdapter listAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
        view=inflater.inflate(R.layout.tuijian,null);
        mythread my=new mythread();
        my.start();
        try {
            my.join();
        }catch (Exception e){
            e.printStackTrace();
        }
        initView();
        return view;
    }

    private void initView(){
        myText=new MyText(this.getContext());
        ListViewScroll lv=(ListViewScroll) view.findViewById(R.id.tjllistView);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int i, long l) {
                Intent intent=new Intent(MainActivity.activity, ArticleDetailActivity.class);
                intent.putExtra("文章",gzMess[i][4]);
                startActivity(intent);
            }
        });
        lv.setDivider(null);
        MyListAdpater mla=new MyListAdpater(GuanZhuFragment.this.getContext());
        lv.setAdapter(mla);
    }

    private class MyListAdpater extends BaseAdapter{
        private LayoutInflater mInflater=null;
        private MyListAdpater(Context context){
            this.mInflater=LayoutInflater.from(context);
        }
        @Override
        public int getCount() {
            if(ls.size()!=0){
                return gzMess.length;
            }else{
                return 0;
            }
        }
        @Override
        public Object getItem(int arg0) {
            return null;
        }

        @Override
        public long getItemId(int arg0) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewClass viewClass;
            if (view == null) {
                view = mInflater.inflate(R.layout.tuijianshow, null);
                viewClass=new ViewClass();
                viewClass.imgageView1=(ImageView)view.findViewById(R.id.tuijian_user_img);
                viewClass.imageView=(ImageView)view.findViewById(R.id.tuijianshow_art_pic);
                viewClass.textView=(TextView)view.findViewById(R.id.tuijian_username);
                viewClass.textViewadd=(TextView)view.findViewById(R.id.tuijianshow_art_text);
                view.setTag(viewClass);
            }else {
                viewClass=(ViewClass)view.getTag();
            }
            viewClass.imgageView1.setImageBitmap(gzBitmap[i][0]);
            viewClass.imageView.setImageBitmap(gzBitmap[i][1]);
            viewClass.textViewadd.setText(gzMess[i][3]);
            viewClass.textView.setText(gzMess[i][1]);
            return view;
        }
        class ViewClass{
            ImageView imgageView1;//人物图片;
            ImageView imageView;//文章图片
            TextView textView;//用户名称
            TextView textViewadd;//文章内容
        }
    }
    public class mythread extends Thread{
        @Override
        public void run(){
            ls=new ArrayList<String[]>();
            ls=NetInfoUtil.getgz(Constant.UserId);
            if (!ls.isEmpty()&&ls.size()!=0){
                gzMess= StrListChange.ListToTwoStringArray(ls);
            }
            gzBitmap=new Bitmap[ls.size()][2];
            for (int i=0;i<ls.size();i++)
            {
                if (MyGetBitmap.isEmpty(gzMess[i][0].trim())){
                    pic=NetInfoUtil.getLuXianImg(gzMess[i][0].trim());
                    gzBitmap[i][0]=MyGetBitmap.getBitmapFromByteArray(pic);
                    gzBitmap[i][0]=MyGetBitmap.zoomImg(gzBitmap[i][0],200,200);
                    MyGetBitmap.setInSDBitmap(pic,gzMess[i][0].trim());
                }
                else {
                    gzBitmap[i][0]=MyGetBitmap.getSDBitmap(gzMess[i][0].trim());
                    gzBitmap[i][0]=MyGetBitmap.zoomImg(gzBitmap[i][0],200,200);
                    if (MyGetBitmap.bitmap!=null&&!MyGetBitmap.bitmap.isRecycled())
                    {
                        MyGetBitmap.bitmap=null;
                    }
                }
                if (MyGetBitmap.isEmpty(gzMess[i][2].trim())){
                    pic=NetInfoUtil.getLuXianImg(gzMess[i][2].trim());
                    gzBitmap[i][1]=MyGetBitmap.getBitmapFromByteArray(pic);
                    gzBitmap[i][1]=MyGetBitmap.zoomImg(gzBitmap[i][1],200,200);
                    MyGetBitmap.setInSDBitmap(pic,gzMess[i][2].trim());
                }else {
                    gzBitmap[i][1]=MyGetBitmap.getSDBitmap(gzMess[i][2].trim());
                    gzBitmap[i][1]=MyGetBitmap.zoomImg(gzBitmap[i][1],200,200);
                if (MyGetBitmap.bitmap!=null&&!MyGetBitmap.bitmap.isRecycled())
                {
                    MyGetBitmap.bitmap=null;
                }
            }
            }
        }
    }
//    //加载中相关
//    private LoadingDiolog dialog;
//    private Handler handler=new Handler(){
//        @Override
//        public void handleMessage(Message mes){
//            switch (mes.what) {
//                case 0:
//                    initView();
//                    dialog.dismiss();
//                    break;
//                default:break;
//            }
//        }
//    };
//
//    @Override
//    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
//    {
//        view=inflater.inflate(R.layout.tuijian,container,false);
//        dialog=LoadingDiolog.show(MainActivity.activity,"加载中",true,null);
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                GetGuanzhuInfoThread getgzInfo=new GetGuanzhuInfoThread();
//                getgzInfo.run();
//            }
//        }).start();
//        name=(TextView)view.findViewById(R.id.username);
//        //     namee=name.getText().toString();
//
//
////        tjgz=view.findViewById(R.id.tjguanzhu);
////        tjgz.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View view) {
////                if(Constant.UserId==null)
////                {
////                    Toast.makeText(MainActivity.activity,"请先登录", Toast.LENGTH_LONG).show();
////                    Intent intent = new Intent(MainActivity.activity, LoginActivity.class);
////                    startActivity(intent);
////                }else {
////                   tjgz.setText("已关注");
////                    //namee=(String)name.getText().toString();//ok 了
////                   NetInfoUtil.yjgz(Constant.UserId+"#"+"123");
////                }
////            }
////        });
//
//        return view;
//    }
//
//    private void initView()
//    {
//        font=Typeface.createFromAsset(MainActivity.activity.getAssets(),"fonts/cjsgyjt.ttf");
//        listView=(ListView)view.findViewById(R.id.tjlistView);
//        initListView();
//    }
//
//    private void initListView(){
//        listAdapter=new MyListAdapter(GuanZhuFragment.this.getContext());
//        listView.setAdapter(listAdapter);
//        listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
//            @Override
//            public void onItemClick(AdapterView<?> adapterView,View view,int i,long l){
//                Intent intent=new Intent(MainActivity.activity, ArticleDetailActivity.class);
//                intent.putExtra(Constant.articleID,gzMess[i][0]);
//                startActivity(intent);
//            }
//        });
//    }
//
//    private class GetGuanzhuInfoThread extends Thread{
//        @Override
//        public void run()
//        {
//            ls=new ArrayList<String[]>();
//            ls= NetInfoUtil.getgz();//关注,用户名称,用户作品图片,作品介绍
//            if (!ls.isEmpty()&&ls.size()!=0){
//                gzMess= StrListChange.ListToTwoStringArray(ls);
//            }
//            gzBitmap=new Bitmap[ls.size()][2];
//            for (int i=0;i<ls.size();i++)
//            {
//                if (MyGetBitmap.isEmpty(gzMess[i][0].trim())){
//                    pic=NetInfoUtil.getLuXianImg(gzMess[i][0].trim());
//                    gzBitmap[i][0]=MyGetBitmap.getBitmapFromByteArray(pic);
//                    gzBitmap[i][0]=MyGetBitmap.zoomImg(gzBitmap[i][0],200,200);
//                    MyGetBitmap.setInSDBitmap(pic,gzMess[i][0].trim());
//                }else {
//                    gzBitmap[i][0]=MyGetBitmap.getSDBitmap(gzMess[i][0].trim());
//                    gzBitmap[i][0]=MyGetBitmap.zoomImg(gzBitmap[i][0],200,200);
//                    if (MyGetBitmap.bitmap!=null&&!MyGetBitmap.bitmap.isRecycled())
//                    {
//                        MyGetBitmap.bitmap=null;
//                    }
//                }if (MyGetBitmap.isEmpty(gzMess[i][2].trim())){
//                pic=NetInfoUtil.getLuXianImg(gzMess[i][2].trim());
//                gzBitmap[i][1]=MyGetBitmap.getBitmapFromByteArray(pic);
//                gzBitmap[i][1]=MyGetBitmap.zoomImg(gzBitmap[i][1],200,200);
//                MyGetBitmap.setInSDBitmap(pic,gzMess[i][2].trim());
//            }else {
//                gzBitmap[i][1]=MyGetBitmap.getSDBitmap(gzMess[i][2].trim());
//                gzBitmap[i][1]=MyGetBitmap.zoomImg(gzBitmap[i][1],200,200);
//                if (MyGetBitmap.bitmap!=null&&!MyGetBitmap.bitmap.isRecycled())
//                {
//                    MyGetBitmap.bitmap=null;
//                }
//            }
//            }
//            Message message=new Message();
//            message.what=0;
//            handler.sendMessage(message);
//            dialog.dismiss();
//        }
//    }
//
//    private class MyListAdapter extends BaseAdapter {
//        private LayoutInflater mInflaterV = null;
//
//        private MyListAdapter(Context context){
//            this.mInflaterV=LayoutInflater.from(context);
//        }
//        @Override
//        public int getCount(){
//            return gzMess.length;
//        }
//        @Override
//        public Object getItem(int i){
//            return  i;
//        }
//        @Override
//        public long getItemId(int i){
//            return i;
//        }
//        @Override
//        public View getView(int i, View view, ViewGroup viewGroup) {
//            ViewClass viewClass;
//            if (view == null) {
//                view = mInflaterV.inflate(R.layout.tuijianlan, null);
//                viewClass=new ViewClass();
//                viewClass.imgageView1=(ImageView)view.findViewById(R.id.user_img);
//                viewClass.imageView=(ImageView)view.findViewById(R.id.tuijianlanwenzhangpic);
//                viewClass.textView=(TextView)view.findViewById(R.id.username);
//                viewClass.textViewadd=(TextView)view.findViewById(R.id.tuijianlanwenzhangjs);
//                view.setTag(viewClass);
//            }else {
//                viewClass=(ViewClass)view.getTag();
//            }
//            viewClass.imgageView1.setImageBitmap(gzBitmap[i][0]);
//            viewClass.imageView.setImageBitmap(gzBitmap[i][1]);
//            viewClass.textViewadd.setText(gzMess[i][3]);
//            viewClass.textView.setText(gzMess[i][1]);
//            return view;
//        }
//        //对控件的实例进行缓存,不需要每次都通过findViewById()方法获取控件实例
//        class ViewClass{
//            ImageView imgageView1;//人物图片;
//            ImageView imageView;//文章图片
//            TextView textView;//用户名称
//            TextView textViewadd;//文章内容
//        }
//    }
}

package com.bn.article;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.bn.myutil.LoadingDiolog;
import com.bn.util.MyGetBitmap;
import com.bn.util.NetInfoUtil;
import com.bn.util.StrListChange;
import com.bn.zol.R;
import com.bn.zolandroid.MainActivity;

import java.util.ArrayList;
import java.util.List;

public class TuiJianFragment extends Fragment {
    View view;
    private List<String[]> ls;//获取数据的列表

    private ConvenientBanner convenientBanner;//广告栏
    private String[][] GuangStr;//存放文章广告栏信息
    private Bitmap[] guangBitmap;//广告栏图片
    byte pic[]; //图片字节数组
    private List<Integer> gglimgs=new ArrayList<>();

    private String[][] ArticleMess;//文章信息
    private ListView listView;//文章推荐
    private MyListAdapter listAdapter;//列表布局适配器
    private Bitmap[] ArticleBitmap;//文章图片
    Typeface font;

    //加载中相关
    private LoadingDiolog dialog;
    private Handler handler=new Handler(){
        @Override
        public void handleMessage(Message mes){
            switch (mes.what) {
                case 0:
                    initView();
                    dialog.dismiss();
                    break;
                default:break;
            }
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        view=inflater.inflate(R.layout.article,container,false);
        //显示加载中对话框
        dialog= LoadingDiolog.show(MainActivity.activity,"加载中......",true,null);
        new Thread(new Runnable() { //获取内容
            @Override
            public void run() {
                GetArticleInfoThread getArticleInfo=new GetArticleInfoThread();
                getArticleInfo.run();
            }
        }).start();
        return view;
    }

    //初始化界面
    private void initView(){
        //获取古典字体
        font= Typeface.createFromAsset(MainActivity.activity.getAssets(),"fonts/cjsgyjt.ttf");
        //广告栏
        convenientBanner=(ConvenientBanner)view.findViewById(R.id.articleconvenientBanner);
        convenientBanner.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                Intent intent=new Intent(getActivity(), ArticleDetailActivity.class);
                intent.putExtra("文章",GuangStr[position][2]);
                startActivity(intent);
            }
        });
        initBanner();
        listView=(ListView)view.findViewById(R.id.articleListView);
        initListView();
    }

    //初始化推荐文章
    private void initListView(){
        listAdapter=new MyListAdapter(TuiJianFragment.this.getContext());
        listView.setAdapter(listAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> adapterView,View view,int i,long l){
                Intent intent=new Intent(getActivity(),ArticleDetailActivity.class);
                intent.putExtra("文章",ArticleMess[i][0]);
                startActivity(intent);
            }
        });
    }

    //初始化广告栏
    private void initBanner(){
        for (int i=0;i<GuangStr.length;i++){
            gglimgs.add(i);
        }
        convenientBanner.setPages(new CBViewHolderCreator() {
            @Override
            public Object createHolder() {
                return new LocalImageHolderView();
            }
        },gglimgs)//设置需要切换的View
                .setPointViewVisible(true)  //设置指示器是否可见
                //设置两个点图片作为翻页指示器,不设置则没有指示器,可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                .setPageIndicator(new int[]{R.drawable.d1, R.drawable.d2})
                //设置指示器位置(左、中、右)
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
                .startTurning(2000)//设置自动切换(同时设置了切换时间)
                .setManualPageable(true); //设置手动影响(设置了该项能否手动切换)//设置点击监听事件
    }



    private class GetArticleInfoThread extends Thread{
        @Override
        public void run(){
            ls=new ArrayList<String[]>();
            ls= NetInfoUtil.getArticle();
            if (!ls.isEmpty()&&ls.size()!=0){
                ArticleMess= StrListChange.ListToTwoStringArray(ls);

            //开辟内存
            ArticleBitmap=new Bitmap[ls.size()];
            for (int i=0;i<ls.size();i++){
                if (MyGetBitmap.isEmpty(ArticleMess[i][1].trim())){
                    pic= NetInfoUtil.getLuXianImg(ArticleMess[i][1].trim());
                    ArticleBitmap[i]= MyGetBitmap.getBitmapFromByteArray(pic);
                    ArticleBitmap[i]= MyGetBitmap.zoomImg(ArticleBitmap[i],200,200);
                    MyGetBitmap.setInSDBitmap(pic,ArticleMess[i][1].trim());
                }else {
                    ArticleBitmap[i]= MyGetBitmap.getSDBitmap(ArticleMess[i][1].trim());
                    //缩小大小
                    ArticleBitmap[i]= MyGetBitmap.zoomImg(ArticleBitmap[i],200,200);
                    //不等于null就设置成null
                    if(MyGetBitmap.bitmap!=null&&!MyGetBitmap.bitmap.isRecycled()){
                        MyGetBitmap.bitmap=null;
                    }
                }
            }
        }
            ls= NetInfoUtil.getArticleGuangGao();//获取文章广告
            if (!ls.isEmpty()&&ls.size()!=0){
                GuangStr= StrListChange.ListToTwoStringArray(ls);
            }
            guangBitmap=new Bitmap[GuangStr.length];
            for (int i=0;i<ls.size();i++){
                if(MyGetBitmap.isEmpty(GuangStr[i][0].trim())){
                    pic=null;
                    pic= NetInfoUtil.getLuXianImg(GuangStr[i][0].trim());
                    guangBitmap[i]= MyGetBitmap.getBitmapFromByteArray(pic);
                    MyGetBitmap.setInSDBitmap(pic,GuangStr[i][0].trim());
                }else {
                    guangBitmap[i]= MyGetBitmap.getSDBitmap(GuangStr[i][0].trim());
                    if (MyGetBitmap.bitmap!=null&&!MyGetBitmap.bitmap.isRecycled()){
                        MyGetBitmap.bitmap=null;
                    }
                }
            }
            Message message=new Message();
            message.what=0;
            handler.sendMessage(message);
            dialog.dismiss();
        }
    }

    public class LocalImageHolderView implements Holder<Integer> {
        private ImageView imageView;
        @Override
        public View createView(Context context) {
            imageView = new ImageView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            return imageView;
        }
        @Override
        public void UpdateUI(Context context, int position, Integer data) {
            imageView.setImageBitmap(guangBitmap[data]);
        }
    }

    private class MyListAdapter extends BaseAdapter{
        private LayoutInflater mInflaterV=null;
        private MyListAdapter(Context context){
            //根据context上下文加载布局,这里的是Demo17Activity本身,即this
            this.mInflaterV=LayoutInflater.from(context);
        }
        @Override
        public int getCount(){
            if(ArticleMess.length!=0)
            {
            return ArticleMess.length;
            }else{
            return 0;
            }
        }
        @Override
        public Object getItem(int i){
            return i;
        }
        @Override
        public long getItemId(int i){
            return i;
        }
        @Override
        public View getView(int i,View view,ViewGroup viewGroup){
            ViewClass viewClass;
            if (view==null){
                view=mInflaterV.inflate(R.layout.article_tj_item,null);
                viewClass=new ViewClass();
                viewClass.article_pic=(ImageView)view.findViewById(R.id.article_pic);
                viewClass.name=(TextView)view.findViewById(R.id.article_name);
                viewClass.author_name=(TextView)view.findViewById(R.id.article_writer);
                viewClass.date=(TextView)view.findViewById(R.id.article_date) ;
                view.setTag(viewClass);
            }else {
                viewClass=(ViewClass)view.getTag();
            }
            viewClass.article_pic.setImageBitmap(ArticleBitmap[i]);
            viewClass.name.setText(ArticleMess[i][2]);
            viewClass.author_name.setText("作者:"+ArticleMess[i][3]);
            viewClass.date.setText(ArticleMess[i][4].substring(0,16));
            return view;
        }
        //对控件的实例进行缓存,不需要每次都通过findViewById()方法获取控件实例
        class ViewClass{
            ImageView article_pic;//文章图片
            TextView name;//文章名称
            TextView author_name;//作者名称
            TextView date;
        }
    }

}

请问ArrayList这个加入的fragment是有次序问题吗?为什么我现在这里的添加顺序app运行会死机加载不出或者有时会黑屏有时会一直加载中 把两个一调换过来一点问题没有 我是想把viewpager里的两个fragment调换一下位置 结果本来没错换了之后反而出错了,app的server端代码也跳红了安卓端里没有跳红
下面是布局xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.bn.article.HomeFragment"
    android:background="@color/white">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/white">
        <LinearLayout
            android:id="@+id/home_title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:background="@color/white">
            <Button
                android:id="@+id/title1"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:textSize="17sp"
                android:layout_margin="0dp"
                android:text="关注"
                android:gravity="center"
                android:background="@drawable/homebutton"
                android:textColor="@color/black"/>
            <Button
                android:id="@+id/title2"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:textSize="17sp"
                android:text="推荐"
                android:gravity="center"
                android:background="@drawable/homebutton"
                android:textColor="@color/black"/>
        </LinearLayout>
    </FrameLayout>

    <LinearLayout
        android:id="@+id/xian"
        android:layout_width="fill_parent"
        android:layout_height="3dp"
        android:background="@color/white"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/biaoqian"
            android:layout_gravity="center">
        </ImageView>
    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"/>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/myviewpager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="12">
    </androidx.viewpager.widget.ViewPager>
</LinearLayout>

2个回答

ArrayList顾名思义,是基于数组连续存储的,所以是有顺序的。先sdd的在前面。

qq_43006674
qq_43006674 那我反过来add为何会报错
大约一个月之前 回复

当然是有次序的,ArrayList的存储结构是数组 数组是有下标的 所以说ArrayList存取肯定是有序的。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐