综合1




//频道管理	

	//1. 在app的gradle里面
implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    implementation 'com.android.support:design:28.0.0'
    implementation project(':pullToRefreshlibrary')
    implementation project(':xlistview')
    android {
        useLibrary 'org.apache.http.legacy'
    }
    implementation  'com.github.andyoom:draggrid:v1.0.1'
 
	/*
	2.在项目的build.gradle中添加
    	maven {url "https://jitpack.io"}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://jitpack.io"
        }

    }
}
*/


	//3.权限
  
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <!-- 在SDCard中创建与删除文件权限 -->
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
    <!-- 往SDCard写入数据权限 -->

    <!-- 震动权限 -->
    <uses-permission android:name="android.permission.VIBRATE"/>
	//4.在功能清单中配置ChannelActivity
   <activity android:name="com.andy.library.ChannelActivity"></activity>

//https://github.com/andyoom/draggrid

//引导页
public class YiDaoYe_Activity extends AppCompatActivity {

    private ViewPager pager;
    private RadioGroup rg;
    private int[] arrs;
    private ArrayList<ImageView> list;
    private Button button;
    private TextView text;
    int time=5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yi_dao_ye_);

        //1sp
        SharedPreferences sp = getSharedPreferences("ydy", Context.MODE_PRIVATE);
        //5判断是否为第一次
        if(sp.getBoolean("如果是第一次",false)){
            //不是直接跳转不引导不动画
            Intent intent = new Intent(YiDaoYe_Activity.this, MainActivity.class);
            startActivity(intent);
            finish();

        }


        //2编辑器
        SharedPreferences.Editor edit = sp.edit();
        //3编辑信息
        edit.putBoolean("如果是第一次",true);
        //4提交
        edit.commit();


        //控件
        pager = findViewById(R.id.pager);
        rg = findViewById(R.id.rg);
        button = findViewById(R.id.button);
        text = findViewById(R.id.text);
        //数据
        arrs = new int[]{R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e};
       //创建图片集合
        list = new ArrayList<>();

        //创建小圆点
       for (int i=0;i<arrs.length;i++) {
           ImageView imageView = new ImageView(YiDaoYe_Activity.this);
           imageView.setImageResource(arrs[i]);
           list.add(imageView);
           RadioButton button = new RadioButton(YiDaoYe_Activity.this);
           rg.addView(button);
       }
        //适配器
        pager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return list.size();
            }

            @Override
            public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
                return view==o;
            }

            @NonNull
            @Override
            public Object instantiateItem(@NonNull ViewGroup container, int position) {
                ImageView imageView = list.get(position);
                container.addView(imageView);
                return imageView;
            }

            @Override
            public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
                container.removeView((View) object);
            }
        });

       //默认第一个
        rg.check(rg.getChildAt(0).getId());


        //滑动监听
        pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                if(i==list.size()-1){
                    //显示
                        button.setVisibility(View.VISIBLE);
                        text.setVisibility(View.VISIBLE);
                        //点击跳转
                       button.setOnClickListener(new View.OnClickListener() {
                           @Override
                           public void onClick(View v) {
                               //跳转
                               Intent intent = new Intent(YiDaoYe_Activity.this, MainActivity.class);
                               startActivity(intent);
                               finish();
                           }
                       });
                       //发送消息
                       handler.sendEmptyMessageDelayed(0,1000);


                 }else{
                    //隐藏
                    button.setVisibility(View.GONE);
                    text.setVisibility(View.GONE);
                    handler.removeCallbacksAndMessages(null);
                }
                //选中
                 rg.check(rg.getChildAt(i).getId());

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });




    }
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            if(time==0){
                handler.removeCallbacksAndMessages(null);
                Intent intent = new Intent(YiDaoYe_Activity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }else{
                time--;
                text.setText(time+"s");
                handler.sendEmptyMessageDelayed(0,1000);
            }


        }
    };

}
///MainAcitity
public class MainActivity extends AppCompatActivity {

    private DrawerLayout dl;
    private RadioGroup rg;
    private FragmentManager manager;
    private XlistView xlistview;
    private Handler handler = new Handler();
    int page=1;

    private ByteArrayOutputStream bos;
    private InputStream inputStream;
    private ArrayList<Datas> newList;
    private boolean netWork;
    private Frag1 frag1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //控件
        dl = findViewById(R.id.dl);
        rg = findViewById(R.id.rg);
        netWork = NetWork.isNetWork(MainActivity.this);


        //监听
        dl.setDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(@NonNull View view, float v) {

            }

            @Override
            public void onDrawerOpened(@NonNull View view) {
                Toast.makeText(MainActivity.this, "开启", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDrawerClosed(@NonNull View view) {
                Toast.makeText(MainActivity.this, "关闭", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDrawerStateChanged(int i) {

            }
        });



        xlistview = findViewById(R.id.xlistview);
        //事务管理者
        manager = getSupportFragmentManager();
        //开启
        final FragmentTransaction transaction = manager.beginTransaction();
        //添加事务
        frag1 = new Frag1();
        final Frag2 frag2 = new Frag2();
        final Frag3 frag3 = new Frag3();
        transaction.add(R.id.fragment, frag1);
        transaction.add(R.id.fragment, frag2);
        transaction.add(R.id.fragment, frag3);
        //显示
        transaction.show(frag1).hide(frag2).hide(frag3);
        //提交
        transaction.commit();
        //默认
        rg.check(R.id.rb1);

        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentTransaction qq = manager.beginTransaction();
                switch (checkedId) {
                    case R.id.rb1:
                        qq.show(frag1).hide(frag2).hide(frag3);
                        break;
                    case R.id.rb2:
                        qq.show(frag2).hide(frag1).hide(frag3);
                        break;
                    case R.id.rb3:
                        qq.show(frag3).hide(frag2).hide(frag1);
                        break;
                }
                qq.commit();
            }
        });

        //设置
        xlistview.setPullLoadEnable(true);
        xlistview.setPullRefreshEnable(true);
        //设置监听
        xlistview.setXListViewListener(new XlistView.IXListViewListener() {



            @Override
            public void onRefresh() {
                if(netWork){
                    page=1;
                    //获得数据
                    getData();
                    //时间
                    getTime();
                }


                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        xlistview.stopRefresh();
                    }
                }, 4000);
            }

            @Override
            public void onLoadMore() {
                if(netWork){
                    page++;
                    //获得数据
                    getData();

                }

                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        xlistview.stopLoadMore();
                    }
                }, 4000);
            }
        });
        if(netWork){
            //获得数据
            getData();
        }







    }
    //时间的方法
    private void getTime() {
        long time = System.currentTimeMillis();
        Date date = new Date(time);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss");
        String s = simpleDateFormat.format(date);
        xlistview.setRefreshTime(s);


    }
    //解析数据
    private void getData() {
        MyAsyncTask myAsyncTask = new MyAsyncTask();
        myAsyncTask.execute();
    }
	//异步类
    class MyAsyncTask extends AsyncTask<String, Integer, String> {


        @Override
        protected String doInBackground(String... strings) {
            String path="http://api.expoon.com/AppNews/getNewsList/type/1/p/"+page;
            try {
                URL url = new URL(path);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("GET");
                conn.setReadTimeout(5000);
                conn.setConnectTimeout(5000);
                if(conn.getResponseCode()==200){
                    inputStream = conn.getInputStream();
                    bos = new ByteArrayOutputStream();
                    byte[] buffer = new byte[1024];
                    int len=0;
                    while((len= inputStream.read(buffer))!=-1){
                        bos.write(buffer,0,len);
                    }

                }
                bos.close();
                inputStream.close();
                String json = bos.toString();
                return json;



            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);

            Gson gson = new Gson();
            Json json = gson.fromJson(s, Json.class);
            ArrayList<Datas> list = json.getData();
            if(page==1){
                newList = new ArrayList<>();
            }
            newList.addAll(list);

            xlistview.setAdapter(new MyXlistAdapter(MainActivity.this,newList));
            //显示新数据
            xlistview.setSelection(newList.size()-(list.size()-1));



        }
    }
    //回传

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //接口回调
        String json = data.getStringExtra("json");
        //传值
        back.getData(json);

       /* //回调数据
        if (listener != null) {
            listener.onJsonData(json);
        }*/

    }

   /* //定义接口回调接口和方法
    public interface OnJsonDataListener {

        void onJsonData(String json);
    }

    //声明接口
    private OnJsonDataListener listener;

    //提供公共的设置监听的方法
    public void setOnJsonDataListener(OnJsonDataListener listener) {
        this.listener = listener;
    }
*/

   //1定义接口
    public interface CallBacks{
        //2定义方法
        void getData(String json);
    }

    //3声明变量
    private CallBacks  back;

    //4set方法
     public void setBack(CallBacks back) {
        this.back = back;
    }
}




//Frag1标签   
public class Frag1 extends Fragment {

    private TabLayout tab;
    private ViewPager pager;
    private ArrayList<String> tabs;
    private ImageView img;
    MainActivity activity;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frag1, container, false);
        //控件
        tab = view.findViewById(R.id.tab);
        pager = view.findViewById(R.id.pager);
        img = view.findViewById(R.id.img);
        //主页面
        activity = (MainActivity) getActivity();


        //数据
        tabs = new ArrayList<>();
        tabs.add("关注");
        tabs.add("热点");
        tabs.add("北京");
        tabs.add("娱乐");

        //点击跳入频道管理
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<ChannelBean> list = new ArrayList<>();
                //十条数据
                for (int i = 0; i < 10; i++) {
                    //
                    ChannelBean channelBean = new ChannelBean("hh" + i, i < 5 ? true : false);
                    list.add(channelBean);
                }

                ChannelActivity.startChannelActivity((AppCompatActivity) getActivity(), list);

            }
        });


        //适配器
        pager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                ChildFragment fragment = new ChildFragment();

                return fragment;
            }

            @Override
            public int getCount() {
                return tabs.size();
            }
            //设置标题


            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return tabs.get(position);
            }
        });

        //关联
        tab.setupWithViewPager(pager);


        return view;
    }

    //获得焦点的方法
    @Override
    public void onResume() {
        super.onResume();
        //Bundle接收值
     /*   Bundle arguments = getArguments();
        String json = arguments.getString("json");*/

     activity.setBack(new MainActivity.CallBacks() {
            @Override
            public void getData(String json) {
                if (json != null) {
                    tabs.clear();
                    tabs.add("关注");
                    tabs.add("热点");
                    tabs.add("北京");
                    tabs.add("娱乐");

                    try {
                   	 //原生解析
                        JSONArray jsonArray = new JSONArray(json);
                        for (int i = 0; i < jsonArray.length(); i++) {
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            String isSelect = jsonObject.getString("isSelect");
                            if (isSelect.equals("true")) {
                                String name = jsonObject.getString("name");
                                tabs.add(name);
                            }
                        }

                        //适配器
                        pager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
                            @Override
                            public Fragment getItem(int i) {
                                ChildFragment fragment = new ChildFragment();

                                return fragment;
                            }

                            @Override
                            public int getCount() {
                                return tabs.size();
                            }
                            //设置标题


                            @Nullable
                            @Override
                            public CharSequence getPageTitle(int position) {
                                return tabs.get(position);
                            }
                        });

                        //关联
                        tab.setupWithViewPager(pager);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                }
            }
        });



//ChildFragment ```
public class ChildFragment extends Fragment {

    private PullToRefreshListView plistview;
    int page=1;
    private Handler handler1=new Handler();
    private boolean netWork;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.child_fragment, container, false);
        plistview = view.findViewById(R.id.plistview);
        //网络判断
        netWork = NetWork.isNetWork(getActivity());


        //设置模式
        plistview.setMode(PullToRefreshBase.Mode.BOTH);

        //设置监听
        plistview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            //下拉刷新
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                if(netWork){
                    page=1;
                    //数据
                    getData();
                }

                   handler1.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                plistview.onRefreshComplete();
                            }
                        },2000);
            }
            //上拉加载
            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {

                if(netWork){
                    page++;
                    //数据
                    getData();

                }

                handler1.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        plistview.onRefreshComplete();
                    }
                },2000);
            }
        });
        if(netWork){
            //数据
            getData();
            Toast.makeText(getActivity(), "有网", Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(getActivity(), "无网", Toast.LENGTH_SHORT).show();
            //查询
            Dao dao = new Dao(getActivity());
            ArrayList<Datas> list = new ArrayList<>();
            ArrayList<Datas> query = dao.query(list);
         /*   Cursor query = dao.query("caches", null, null, null, null, null,null);


            if (query.moveToFirst()) {
                do {
                    String title = query.getString(query.getColumnIndex("title"));
                    String thumbnail_pic_s = query.getString(query.getColumnIndex("thumbnail_pic_s"));
                    list.add(new Datas(title, thumbnail_pic_s));
                } while (query.moveToNext());
            }

            query.close();*/
            plistview.setAdapter(new MyPlistAdapter(getActivity(),query));
        }



        return view;
    }

    private void getData() {
        //开线程
        new Thread(new Runnable() {
            @Override
            public void run() {
                String path ="http://www.xieast.com/api/news/news.php?page="+page;
                //创建网络请求对象
                //父类引用指向子类实现
                HttpClient client = new DefaultHttpClient();
                //创建请求方式
                HttpGet get = new HttpGet(path);

                try {
                    //通过网络请求执行get请求
                    HttpResponse response = client.execute(get);
                    //获取状态码
                    int statusCode = response.getStatusLine().getStatusCode();
                    if (statusCode==200){
                        //获取服务器资源
                        //得到Http实体
                        HttpEntity entity = response.getEntity();
                        //从实体中得到输入流
                        InputStream inputStream = entity.getContent();
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        byte [] buffer = new byte[1024];
                        int len =0;
                        while ((len=inputStream.read(buffer))!=-1){
                            bos.write(buffer,0,len);
                        }
                        inputStream.close();
                        bos.close();
                        String json = bos.toString();

                        //第一种创建消息的方式
                        /*Message message = new Message();
                        message.obj = json;
                        message.what =0;
                        handler.sendMessage(message1);

                        //第二种创建消息的方式
                        Message message1 = Message.obtain();
                        message1.obj = json;
                        message1.what =0;
                        handler.sendMessage(message1);*/

                        //第三种创建消息的方式
                        Message message2 = handler.obtainMessage();
                        message2.obj = json;
                        message2.what =0;
                        handler.sendMessage(message2);


                    }


                } catch (IOException e) {
                    e.printStackTrace();
                }


            }
        }).start();



    }

    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler(){

        private ArrayList<Datas> newData;

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    String json= (String) msg.obj;
                    Gson gson = new Gson();
                    Json json1 = gson.fromJson(json, Json.class);
                    ArrayList<Datas> list = json1.getData();
                    if(page==1){
                        newData = new ArrayList<>();
                        //添加
                        Dao dao = new Dao(getActivity());
                        dao.delete();
                        dao.add(list);

                    }

                    newData.addAll(list);
                    plistview.setAdapter(new MyPlistAdapter(getActivity(),newData));
                    //显示新数据
                    plistview.setSelection(newData.size()-(list.size()-1));


                    break;
            }
        }
    };

}
///数据库
public class MySqlite extends SQLiteOpenHelper {
    public MySqlite(Context context) {
        super(context, "bw.db", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建表
        db.execSQL("create table caches(title TEXT,thumbnail_pic_s TEXT)");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

public class Dao {

    private final SQLiteDatabase db; 

    public Dao(Context context) {
        MySqlite mySqlite = new MySqlite(context);
        db = mySqlite.getWritableDatabase();

    }

    public void add(ArrayList<Datas> list) {
        ContentValues values = new ContentValues();
        for (int i=0;i<list.size();i++){
            values.put("title",list.get(i).getTitle());
            values.put("thumbnail_pic_s",list.get(i).getThumbnail_pic_s());
            db.insert("caches",null,values);
         }
    }

    public void delete() {
        db.delete("caches", null, null);
    }

    public ArrayList<Datas> query(ArrayList<Datas> list){
        Cursor query = db.query("caches", null, null, null, null, null,null);


        if (query.moveToFirst()) {
            do {
                String title = query.getString(query.getColumnIndex("title"));
                String thumbnail_pic_s = query.getString(query.getColumnIndex("thumbnail_pic_s"));
                list.add(new Datas(title, thumbnail_pic_s));
            } while (query.moveToNext());
        }

        query.close();
        return list;

    }
}
//网路
public class NetWork {
    public static boolean isNetWork(Context context){
        ConnectivityManager conn= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = conn.getActiveNetworkInfo();
        if(info!=null){
            return info.isAvailable();
        }
        return false;
    }


}

//PullToRefreshListView 适配器
public class MyPlistAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Datas> list;
    private final static int TYPE_ONE=0;
    private final static int TYPE_TWO=1;
    private DisplayImageOptions build;


    public MyPlistAdapter(Context context, ArrayList<Datas> list) {
        this.context = context;
        this.list = list;
        build=new DisplayImageOptions.Builder()
                .displayer(new RoundedBitmapDisplayer(50))
                .cacheOnDisk(true)
                .build();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {

        position%=2;
        if (position==0){
            return TYPE_ONE;
        }else if(position==1){
            return TYPE_TWO;
        }

       return 0;
    }

    @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) {
        ViewHodler1 viewHodler1=null;
        ViewHodler2 viewHodler2=null;

        int type = getItemViewType(position);
        if(convertView==null){
            if(type==TYPE_ONE){
                convertView=View.inflate(context, R.layout.itme1,null);
                TextView text = convertView.findViewById(R.id.text);
                viewHodler1=new ViewHodler1();
                viewHodler1.text=text;
                convertView.setTag(viewHodler1);
            }else if(type==TYPE_TWO){
                convertView=View.inflate(context, R.layout.itme2,null);
                TextView text = convertView.findViewById(R.id.text);
                ImageView img = convertView.findViewById(R.id.img);
                viewHodler2=new ViewHodler2();
                viewHodler2.text=text;
                viewHodler2.img=img;
                convertView.setTag(viewHodler2);
            }

        }else{
            if(type==TYPE_ONE){
                    viewHodler1= (ViewHodler1) convertView.getTag();
            }else if(type==TYPE_TWO){
                viewHodler2= (ViewHodler2) convertView.getTag();
            }
        }

        if(type==TYPE_ONE){
                viewHodler1.text.setText(list.get(position).getTitle());
        }else if(type==TYPE_TWO){
            viewHodler2.text.setText(list.get(position).getTitle());
            ImageLoader.getInstance().displayImage(list.get(position).getThumbnail_pic_s(),viewHodler2.img,build);

        }



        return convertView;
    }


    class ViewHodler1{
        private TextView text;
    }

    class ViewHodler2{
        private TextView text;
        private ImageView img;
    }
}


//XlistView的适配器
public class MyXlistAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Datas> list;
    private final static int TYPE_ONE=0;
    private final static int TYPE_TWO=1;



    public MyXlistAdapter(Context context, ArrayList<Datas> list) {
        this.context = context;
        this.list = list;
    }




    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {

        position%=2;
        if (position==0){
            return TYPE_ONE;
        }else if(position==1){
            return TYPE_TWO;
        }

       return 0;
    }

    @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) {
        ViewHodler1 viewHodler1=null;
        ViewHodler2 viewHodler2=null;

        int type = getItemViewType(position);
        if(convertView==null){
            if(type==TYPE_ONE){
                convertView=View.inflate(context, R.layout.itme1,null);
                TextView text = convertView.findViewById(R.id.text);
                viewHodler1=new ViewHodler1();
                viewHodler1.text=text;
                convertView.setTag(viewHodler1);
            }else if(type==TYPE_TWO){
                convertView=View.inflate(context, R.layout.itme2,null);
                TextView text = convertView.findViewById(R.id.text);
                ImageView img = convertView.findViewById(R.id.img);
                viewHodler2=new ViewHodler2();
                viewHodler2.text=text;
                viewHodler2.img=img;
                convertView.setTag(viewHodler2);
            }

        }else{
            if(type==TYPE_ONE){
                    viewHodler1= (ViewHodler1) convertView.getTag();
            }else if(type==TYPE_TWO){
                viewHodler2= (ViewHodler2) convertView.getTag();
            }
        }

        if(type==TYPE_ONE){
                viewHodler1.text.setText(list.get(position).getNews_title());
        }else if(type==TYPE_TWO){
            viewHodler2.text.setText(list.get(position).getNews_title());
            ImageLoader.getInstance().displayImage(list.get(position).getPic_url(),viewHodler2.img);

        }



        return convertView;
    }


    class ViewHodler1{
        private TextView text;
    }

    class ViewHodler2{
        private TextView text;
        private ImageView img;
    }




}











相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页