wwww

时间:2024-10-22 07:10:45
public class MainActivity extends AppCompatActivity implements {
   private  int con=1;
    private ViewPager pager;
    private List<String> imagelist=new ArrayList<String>();
    private Handler handler=new Handler(){
        //handler机制设置自动轮播
        @Override
        public void handleMessage(Message msg) {
            int what=;
            (what);
        }
    };
    private XListView xlv;
    private int page=1;
    private boolean flag;
    private List<> list;
    private MyBaseadapter adapter;
    private Button btn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);
        pager = (ViewPager) findViewById();
        btn = (Button) findViewById();
        //放入图片
        ("/1503638093/");
        ("/1503638052/");
        ("/1503637943/");
        ("/6adf461b77359da62787be92e43f086ajpg");
        (new My());
        new Thread(){
            @Override
            public void run() {
                //设置成为无限轮播
                while(true){
                    try {
                        //设置轮播时间
                        (1000);
                        con++;
                        (con);
                    } catch (InterruptedException e) {
                        ();
                    }

                }
            }
        }.start();
        xlv = (XListView) findViewById();
        (true);
        (this);
        data();
        //跳转显示多条目
        (new () {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(MainActivity.this,Main2.class);
                startActivity(intent);
            }
        });

    }
    public void data(){
        jiexi("/json/categories/lol/");
    }
    public void jiexi(String path){
        new AsyncTask<String,Void,String>(){
            @Override
            protected void onPostExecute(String s) {
                if (s!=null){
                    Gson gson=new Gson();
                    Bean bean = (s, Bean.class);
                    //并能在本地打印网络请求的字符串(5分)
                    System.out.print(());
                    //5)将请求获得的网络json字符串,定义实体类(5分),解析到对象中集合中(5分)
                    list = ();
                    if (adapter==null) {
                        adapter = new MyBaseadapter(MainActivity.this, list);
                        (adapter);
                    }else{
                        (list,flag);
                    }

                }
            }

            //        3)异步请求网络数据(5分),
            @Override
            protected String doInBackground(String... params) {
                try {
                    URL url=new URL(params[0]);
                    HttpURLConnection connection = (HttpURLConnection) ();
                    ("GET");
                    (3000);
                    (3000);
                    int code = ();
                    if (code==200){
                        InputStream is = ();
                        return (is);
                    }
                } catch (Exception e) {
                    ();
                }
                return null;
            }
        }.execute(path);

    }
    //        2)实现下拉更多数据功能,注册实现接口(5分),刷新完毕,并弹出Toast提示(5分)
    @Override
    public void onRefresh() {
        flag=false;
        data();
        (true);
        (MainActivity.this,"刷新完毕",Toast.LENGTH_SHORT).show();
    }
    //        2)实现下拉更多数据功能,注册实现接口(5分),刷新完毕,并弹出Toast提示(5分)
    @Override
    public void onLoadMore() {
         flag=true;
        data();
        ();
        (MainActivity.this,"加载完毕",Toast.LENGTH_SHORT).show();
    }

    class My extends PagerAdapter{

        @Override
        public int getCount() {
            //轮播的次数
            return Integer.MAX_VALUE;
        }

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

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            //加载图片
            ImageView imageView=new ImageView(MainActivity.this);
            ().displayImage(imagelist.get(position%()),imageView,());
            (imageView);
            return imageView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            ((View) object);
        }
    }
}
public class Main2 extends AppCompatActivity implements {
    private boolean flag;
    private XListView xlv;
    private List<> list;
    private MyBaseadapter2 adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity2);
        xlv = (XListView) findViewById();
        (true);
        (this);
        data();
    }
    public void data(){
        jiexi("/json/categories/lol/");
    }
    public void jiexi(String path){
        new AsyncTask<String,Void,String>(){
            @Override
            protected void onPostExecute(String s) {
                if (s!=null){
                    //gson解析
                    Gson gson=new Gson();
                    //实体bean类
                    Bean bean = (s, Bean.class);
                   //放到集合中
                    list = ();
                    if (adapter==null) {
                        adapter = new MyBaseadapter2(Main2.this, list);
                        (adapter);
                    }else{
                        (list,flag);
                    }

                }
            }

            //        3)异步请求网络数据(5分),
            @Override
            protected String doInBackground(String... params) {
                try {
                    URL url=new URL(params[0]);
                    HttpURLConnection connection = (HttpURLConnection) ();
                    ("GET");
                    (3000);
                    (3000);
                    int code = ();
                    if (code==200){
                        InputStream is = ();
                        return (is);
                    }
                } catch (Exception e) {
                    ();
                }
                return null;
            }
        }.execute(path);

    }
    public void onRefresh() {
        flag=false;
        data();
        (true);
        (Main2.this,"刷新完毕",Toast.LENGTH_SHORT).show();
    }
    //        2)实现下拉更多数据功能,注册实现接口(5分),刷新完毕,并弹出Toast提示(5分)
    @Override
    public void onLoadMore() {
        flag=true;
        data();
        ();
        (Main2.this,"加载完毕",Toast.LENGTH_SHORT).show();
    }
}
public class MyBaseadapter extends BaseAdapter {
    private Context context;
    private List<> list;
    public MyBaseadapter(Context context,List<> list) {
        this.list=list;
        this.context=context;
    }
    //下拉刷新会在第一条添加内容,上啦加载会在最后一条添加内容
    public void sss(List<> data,boolean flag){
        for ( s:  data) {
            if (flag){
                (s);
            }else{
                (0,s);
            }
        }
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list!=null?():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) {
        ViewHoder hoder=null;
        if (convertView==null){
            hoder=new ViewHoder();
            //查找控件
            convertView=(context,,null);
            = (ImageView) ();
            = (TextView) ();
            = (TextView) ();
            (hoder);
        }else{
            hoder= (ViewHoder) ();
        }
//给每个空间id赋值
        ().displayImage(list.get(position).getApp_shuffling_image(),,());
        (list.get(position).getNick());
        (list.get(position).getTitle());
        return convertView;
    }//,并进行优化(5分)
    class ViewHoder{
        private ImageView image;
        private TextView nick,title;
    }
}
public class MyBaseadapter2 extends BaseAdapter {
    private Context context;
    private List<> list;
    public MyBaseadapter2(Context context,List<> list) {
        this.list=list;
        this.context=context;
    }//下拉刷新会在第一条添加内容,上啦加载会在最后一条添加内容
    public void sss(List<> data,boolean flag){
        for ( s:  data) {
            if (flag){
                (s);
            }else{
                (0,s);
            }
        }
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list!=null?():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) {
        //多条目加载
        if (position%2==0){
            convertView=(context,.item1,null);
            ImageView image1 = (ImageView) (.image1);
            TextView nick1 = (TextView) (.nick1);
            TextView title1 = (TextView) (.title1);
            ().displayImage(list.get(position).getApp_shuffling_image(),image1,());
            (list.get(position).getNick());
            (list.get(position).getTitle());
        }else{
            convertView=(context,.item2,null);
            ImageView image2 = (ImageView) (.image2);
            TextView nick2 = (TextView) (.nick2);
            TextView title2 = (TextView) (.title2);
            ().displayImage(list.get(position).getApp_shuffling_image(),image2,());
            (list.get(position).getNick());
            (list.get(position).getTitle());
        }
        return convertView;
    }

}
<RelativeLayout
    xmlns:android="/apk/res/android"
    xmlns:app="/apk/res-auto"
    xmlns:tools="/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".">

    <.
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:id="@+id/pager"></.>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btn"
        android:text="跳转多条目显示"
        android:layout_below="@+id/pager"/>
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:id="@+id/bar"
        android:layout_below="@+id/btn"
        />
    <
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/xlv"
        android:layout_below="@+id/bar"></>

</RelativeLayout>
<LinearLayout xmlns:android="/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/xlistview"></>
</LinearLayout>

item

<RelativeLayout xmlns:android="/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/image" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sssssssss"
        android:id="@+id/nick"
        android:layout_above="@+id/title"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="22dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/title"
        android:text="ddddddddddddddd"
        android:layout_marginBottom="21dp"
        android:layout_alignBottom="@+id/image"
        android:layout_alignLeft="@+id/nick"
        android:layout_alignStart="@+id/nick" />

</RelativeLayout>

item1

<RelativeLayout xmlns:android="/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/image1" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sssssssss"
        android:id="@+id/nick1"
        android:layout_above="@+id/title1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="22dp" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/title1"
        android:text="ddddddddddddddd"
        android:layout_marginBottom="21dp"
        android:layout_alignBottom="@+id/image1"
        android:layout_alignLeft="@+id/nick1"
        android:layout_alignStart="@+id/nick1" />

</RelativeLayout>

item2

<RelativeLayout xmlns:android="/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher"
        android:layout_alignParentRight="true"/>

    <TextView
        android:id="@+id/nick2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="19dp"
        android:layout_marginStart="19dp"
        android:layout_marginTop="22dp"
        android:text="nick" />

    <TextView
        android:id="@+id/title2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/image2"
        android:layout_alignLeft="@+id/nick2"
        android:layout_alignStart="@+id/nick2"
        android:layout_marginBottom="14dp"
        android:text="TextView" />


</RelativeLayout>

 

相关文章