京东界面之首页全部代码 有点乱

//Java哦

public class Shou extends Fragment{
    private RecyclerView gong;
    private RecyclerView mian;
    private RecyclerView nei;
    private Banner banner;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.shou,null);
        final Banner banner = (Banner) view.findViewById(R.id.banner);
            gong = (RecyclerView) view.findViewById(R.id.gong);
            mian = (RecyclerView) view.findViewById(R.id.mian);
            nei = (RecyclerView) view.findViewById(R.id.nei);



        OkHttp3Util.doGet("http://120.27.23.105/product/getCatagory", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, final Response response) throws IOException {
                if (response.isSuccessful()){
                    final String str = response.body().string();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //1.gson解析
                            Gson gson = new Gson();
                            Gong_Bean gbean = gson.fromJson(str, Gong_Bean.class);
                            List<Gong_Bean.DataEntity> data = gbean.getData();

                            gong.setLayoutManager(new GridLayoutManager(getActivity(),2, OrientationHelper.HORIZONTAL,false));
                            Adapter01 adapter01 = new Adapter01(data,getActivity());

                            gong.setAdapter(adapter01);
                        }
                    });
                }
            }
        });
        OkHttp3Util.doGet("http://120.27.23.105/ad/getAd", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()){
                    final String stri = response.body().string();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //2.gson解析
                            Gson gson = new Gson();
                            Bean gbean2 = gson.fromJson(stri, Bean.class);
                            List<Bean.MiaoshaBean.ListBeanX> list = gbean2.getMiaosha().getList();
                            mian.setLayoutManager(new GridLayoutManager(getActivity(),1,OrientationHelper.HORIZONTAL,false));
                            Adapter adapter = new Adapter(list,getActivity());

                            mian.setAdapter(adapter);
                        }
                    });
                }
            }
        });
        OkHttp3Util.doGet("http://120.27.23.105/ad/getAd", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()){
                    final String strin = response.body().string();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //3.gson解析
                            Gson gson = new Gson();
                            Bean gbean3 = gson.fromJson(strin, Bean.class);
                            List<Bean.TuijianBean.ListBean> list = gbean3.getTuijian().getList();
                            nei.setLayoutManager(new GridLayoutManager(getActivity(),2,OrientationHelper.VERTICAL,false));
                            Adapter03 adapter03 = new Adapter03(list, getActivity());

                            nei.setAdapter(adapter03);

                        }
                    });
                }
            }
        });

        OkHttp3Util.doGet("http://120.27.23.105/ad/getAd", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

                if (response.isSuccessful()){
                    final String s = response.body().string();
                    Log.d("aaa", "run: "+s);
                    getActivity().runOnUiThread(new Runnable() {


                        @Override
                        public void run() {
                            //gson解析
                            Gson gson = new Gson();
                            Bean bean = gson.fromJson(s, Bean.class);
                            List<Bean.DataBean> data = bean.getData();

                            List<String> string = new ArrayList<>();
                            for (int i=0;i<data.size();i++){
                                String icon = data.get(i).getIcon();
                                string.add(icon);

                            }
                            banner.setImageLoader (new Imager());
                            banner.setImages (string);
                            banner.start ();

                        }
                    });

                }
            }
        });
        return view;
    }



}

//Java还有三个界面...大概都是这样的
public class Mine extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.mine,null);
        return view;
    }
}


//xml四个文件...
//第一个首页的
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.youth.banner.Banner
            android:id="@+id/banner"
            android:layout_width="match_parent"
            android:layout_height="310px"></com.youth.banner.Banner>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/gong"
            android:layout_width="match_parent"
            android:layout_height="410px"></android.support.v7.widget.RecyclerView>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/mian"
            android:layout_width="match_parent"
            android:layout_height="210px"></android.support.v7.widget.RecyclerView>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/nei"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
    </LinearLayout>
</ScrollView>
//第二个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:background="#A1CC3B"
    android:layout_height="match_parent">

</LinearLayout>
//第二个第三个第四个都没有写.....就定义了一个颜色

//首页里面的XML

//第一个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="29dp"
        app:srcCompat="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="100dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:text="TextView" />
</RelativeLayout>
//第二个

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="29dp"
        android:src="@mipmap/ic_launcher"/>
    <TextView
        android:id="@+id/textView1"
        android:layout_width="80dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_marginTop="13dp"
        android:text="TextView"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true" />
</RelativeLayout>
//第三个

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginTop="16dp"
        android:src="@mipmap/ic_launcher"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
    <TextView
        android:maxLines="2"
        android:minLines="2"
        android:id="@+id/textView2"
        android:layout_width="80dp"
        android:gravity="center"
        android:layout_height="wrap_content"
        android:layout_marginTop="13dp"
        android:text="TextView"
        android:layout_below="@+id/imageView2"
        android:layout_alignLeft="@+id/imageView2"
        android:layout_alignStart="@+id/imageView2" />
</RelativeLayout>
//有点繁琐.....

//还有其它类

//Myappter

public class Myappter extends Application {
    @Override
    public void onCreate() {
        super.onCreate ( );
        ImageLoaderConfiguration configuration=new ImageLoaderConfiguration .Builder (this)
                .build ();
        ImageLoader.getInstance ().init (configuration);
    }
}
//Imager

public class Imager extends ImageLoader {
    @Override
    public void displayImage(Context context, Object path, ImageView imageView) {
        Glide.with (context).load (path).into (imageView);
    }
}
//Bean类有两个...
//网址是
http://120.27.23.105/product/getCatagory
//Gong_Bean

http://120.27.23.105/ad/getAd
//Bean

//接下来就是Adapter了...首先是第一个

//上面的代码Adapter顺序有错误

//这是第一个应该打的

//名字Adapter02

public class Adapter02 extends RecyclerView.ViewHolder {
    public ImageView img;
    public TextView tex;
    public ImageView img1;
    public TextView tex1;
    public ImageView img2;
    public TextView tex2;
    public Adapter02(View itemView) {

        super(itemView);
        img2 = (ImageView) itemView.findViewById(R.id.imageView2);
        tex2 = (TextView) itemView.findViewById(R.id.textView2);
        tex1 = (TextView) itemView.findViewById(R.id.textView1);
        img1 = (ImageView) itemView.findViewById(R.id.imageView1);
        img = (ImageView) itemView.findViewById(R.id.imageView);
        tex = (TextView) itemView.findViewById(R.id.textView);
    }
}
//第二个

//名字Adapter01

public class Adapter01 extends RecyclerView.Adapter<Adapter02> {
    private List<Gong_Bean.DataEntity> data;
    private Context context;

    public Adapter01(List<Gong_Bean.DataEntity> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public Adapter02 onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.shitu01,null);
        Adapter02 adapter02 = new Adapter02(view);
        //視圖

        return adapter02;
    }

    @Override
    public void onBindViewHolder(Adapter02 holder, int position) {
        holder.tex.setText(data.get(position).getName());
        Glide.with(context).load(data.get(position).getIcon()).into(holder.img);
        //找到控件之後賦值

    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}
//第三个

//名字Adapter

public class Adapter extends RecyclerView.Adapter<Adapter02> {
    List<Bean.MiaoshaBean.ListBeanX>  data;
    private Context context;

    public Adapter(List<Bean.MiaoshaBean.ListBeanX>  data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public Adapter02 onCreateViewHolder(ViewGroup parent, int viewType) {
        //视图
        View view = View.inflate(context, R.layout.shitu02,null);
        Adapter02 adapter02 = new Adapter02(view);
        return adapter02;
    }

    @Override
    public void onBindViewHolder(Adapter02 holder, int position) {
        //找到控件之后赋值
        holder.tex1.setText(data.get(position).getTitle());
        Glide.with(context).load(data.get(position).getImages().split("\\|")[0]).into(holder.img1);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}

//第四个

//名字Adapter03

public class Adapter03 extends RecyclerView.Adapter<Adapter02> {
    private List<Bean.TuijianBean.ListBean> data;
    private Context context;

    public Adapter03(List<Bean.TuijianBean.ListBean> data, Context context) {
        this.data = data;
        this.context = context;
    }


    @Override
    public Adapter02 onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.shitu03,null);
        Adapter02 adapter02 = new Adapter02(view);

        return adapter02;
    }

    @Override
    public void onBindViewHolder(Adapter02 holder, int position) {
        holder.tex2.setText(data.get(position).getTitle());
        Glide.with(context).load(data.get(position).getImages().split("\\|")[0]).into(holder.img2);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }
}

//依赖

compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.youth.banner:banner:1.4.9'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.squareup.okio:okio:1.11.0'
testCompile 'junit:junit:4.12'
compile 'com.github.bumptech.glide:glide:3.6.1'

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值