主頁 > 移動端開發 > 【Android專案實戰 | 從零開始寫app(11)】實作app首頁功能&九宮格服務分類&熱門推薦&新聞串列

【Android專案實戰 | 從零開始寫app(11)】實作app首頁功能&九宮格服務分類&熱門推薦&新聞串列

2021-04-27 18:05:19 移動端開發

說在前面,由于各種adapter,xml布局,bean物體類,Activity,也為了讓看懂,代碼基本都是“簡單粗暴直接不好看”,沒啥okhttp和util工具類之類的封裝,本篇幅可能有點長吧,大佬請放過,哈~

菜雞一枚,寫得不好,有問題的請指教~~

本篇實作效果:

RecyclerView+json+okhttp+glide實作服務分類和熱門主題推薦,顯示,自定義介面實作RecyclerView 子item的點擊事件,點擊對應的item 進入對應的服務,熱門詳情頁面,直接用簡單的Intent 資料傳遞新聞詳情資訊,也可用WebView 加載新聞詳情,
在這里插入圖片描述

文章內容

  • 本篇實作效果:
  • 文章導航
  • 功能邏輯實作
  • 首頁
  • 布局
    • fragment_home.xml:
    • service.item.xml:
    • recommend_item.xml:
    • news_item.xml
  • 配接器
    • NewsAdapter
    • NewTabAdapter
    • RecommendAdapter
    • RecycleServiceAdapter
  • 跳轉詳情頁面
    • 關于點擊跳轉對應的Activity
    • CityStateAcivity:
  • 關于布局
  • 物體類
    • CommentBean:
    • RecommentBean:
    • ResponseBean:
    • ServiceBean:

文章導航

一、【Android專案實戰 | 從零開始寫app(一)】 創建專案

二、【Android專案實戰 | 從零開始寫app(二)】實作閃屏頁,啟動app

三、【Android專案實戰 | 從零開始寫app(三)】實作引導頁,進入登錄or主頁面

四、【Android專案實戰 | 從零開始寫app(四)】Okhttp+Gson實作服務端登錄驗證功能

五、【Android專案實戰 | 從零開始寫app(五)】okhttp+gson實作服務端注冊功能

六、【Android專案實戰 | 從零開始寫app(六)】用TabLayout+ViewPager搭建App 框架主頁面底部導航欄

七、【Android專案實戰 | 從零開始寫app(七)】優化主頁導航欄,禁用主頁頁面滑動切換效果

八、【Android專案實戰 | 從零開始寫app(八)】實作app首頁廣告輪播圖切換和搜索跳轉

九、【Android專案實戰 | 從零開始寫app(九)】實作主頁底部新聞模塊資料的決議

十、【Android專案實戰 | 從零開始寫app(10)】Okhttp+glide+json+ListView實作新聞模塊資料的填充顯示

十一、【Android專案實戰 | 從零開始寫app(11)】實作app首頁九宮格服務分類點擊跳轉

十二、【Android專案實戰 | 從零開始寫app(12)】實作app首頁熱門推薦

十三、【Android專案實戰 | 從零開始寫app(13)】實作服務頁面資料的決議

十四、【Android專案實戰 | 從零開始寫app(14)】實作用戶中心模塊清除token退出登錄&資訊修改等功能

十五、【Android專案實戰 | 從零開始寫app(15)】實作發布模塊…


功能邏輯實作

首頁

在HomeFragment 加入如下代碼:

package com.example.myapp.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.myapp.R;
import com.example.myapp.activity.ApponitmentActivity;
import com.example.myapp.activity.BannerWebView;
import com.example.myapp.activity.BusActivity;
import com.example.myapp.activity.CityStateActivity;
import com.example.myapp.activity.LivingPayActivity;
import com.example.myapp.activity.NewSearchActivity;
import com.example.myapp.activity.NewsWebViewActivity;
import com.example.myapp.activity.ParkActivity;
import com.example.myapp.activity.RecommendWebView;
import com.example.myapp.activity.WeiZhangActivity;
import com.example.myapp.adapter.NewTabAdapter;
import com.example.myapp.adapter.RecommendAdapter;
import com.example.myapp.adapter.RecycleServiceAdapter;
import com.example.myapp.bean.BannerBean;
import com.example.myapp.bean.NewsBean;
import com.example.myapp.bean.RecommendBean;
import com.example.myapp.bean.ServiceBean;
import com.example.myapp.utils.APIConfig;
import com.google.android.material.tabs.TabLayout;
import com.google.gson.Gson;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerImageAdapter;
import com.youth.banner.holder.BannerImageHolder;
import com.youth.banner.indicator.CircleIndicator;
import com.youth.banner.listener.OnBannerListener;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @ProjectName: MyApp
 * @Package: com.example.myapp.fragment
 * @ClassName: HomeFragment
 * @Description:
 * @Author: liyingxia
 * @CreateDate: 2021/4/13 21:34
 */
public class HomeFragment extends BaseFragment {
    private static final String TAG = HomeFragment.class.getSimpleName();
    private TextView tv_more,tv_theme,tv_theme_title;
    private EditText ed_search;
    private Banner banner;
    private RecyclerView home_recyclerview,home_recyclerview1;
    private RecycleServiceAdapter recycleServiceAdapter;
    private List<ServiceBean.RowsBean> rowsBeanList;
    private List<RecommendBean.RowsDTO> recommendList;
    private RecommendAdapter recommendAdapter;
    private NewsBean newsBean;
    private NewsAdapter newsAdapter;
    private NewTabAdapter newTabAdapter;
    private TabLayout tab_layout;
    private ListView home_listview;
    private ViewPager view_pager;
    private OkHttpClient client = new OkHttpClient();

    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what==0) {
                ServiceBean serviceBean = (ServiceBean) msg.obj;
                rowsBeanList = serviceBean.getRows();
                recycleServiceAdapter= new RecycleServiceAdapter(getActivity(),rowsBeanList);
                home_recyclerview.setLayoutManager(new GridLayoutManager(getActivity(),5));
                home_recyclerview.setAdapter(recycleServiceAdapter);
                recycleServiceAdapter.setItemClickListener(new RecycleServiceAdapter.MyItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        String url = APIConfig.BASE_URL+"/"+rowsBeanList.get(position).getLink();
                        Intent intent = null;
                        if (position==0){
                            intent = new Intent(getActivity(), CityStateActivity.class);
                        } else if (position==1) {
                            intent = new Intent(getActivity(), BusActivity.class);
                        } else if (position==2) {
                            intent = new Intent(getActivity(), ApponitmentActivity.class);
                        } else if (position==3) {
                            intent = new Intent(getActivity(), LivingPayActivity.class);
                        } else if (position==4) {
                            intent = new Intent(getActivity(), WeiZhangActivity.class);
                        } else if (position==5) {
                            intent = new Intent(getActivity(), ParkActivity.class);
                        }
                        Bundle bundle = new Bundle();
                        bundle.putString("title",rowsBeanList.get(position).getServiceName());
                        bundle.putString("url",url);
                        intent.putExtras(bundle);
                        getActivity().startActivity(intent);
                    }
                });
            }
            if (msg.what==1) {
                RecommendBean recommendBean = (RecommendBean) msg.obj;
                recommendList = recommendBean.getRows();
                recommendAdapter = new RecommendAdapter(getActivity(),recommendList);
                home_recyclerview1.setLayoutManager(new GridLayoutManager(getActivity(),2));
                home_recyclerview1.setAdapter(recommendAdapter);
                recommendAdapter.setOnItemClickListener(new RecommendAdapter.OnItemClickListener() {
                    @Override
                    public void onItemClick(int position, List<RecommendBean.RowsDTO> list) {
                        String url = APIConfig.BASE_URL+"/"+list.get(position).getLink();
                        Toast.makeText(getContext(),"url詳情:"+url,Toast.LENGTH_LONG).show();
                        Intent intent = new Intent(getActivity(), RecommendWebView.class);
                        Bundle bundle = new Bundle();
                        bundle.putString("title",list.get(position).getServiceName());
                        bundle.putString("url",url);
                        intent.putExtras(bundle);
                        getActivity().startActivity(intent);
                    }
                });
            }
        }
    };

    @Override
    public View initView() {
        Log.i(TAG, "首頁的視圖被初始化了");
        View view = View.inflate(getContext(), R.layout.fragment_home, null);
        ed_search = view.findViewById(R.id.ed_search);
        banner = view.findViewById(R.id.banner);
        home_recyclerview = view.findViewById(R.id.home_recyclerview);
        home_recyclerview1 = view.findViewById(R.id.home_recyclerview1);
        home_listview = view.findViewById(R.id.home_listview);
        tab_layout = view.findViewById(R.id.tab_layout);
        view_pager = view.findViewById(R.id.view_pager);
        tv_more = view.findViewById(R.id.tv_more);
        tv_theme = view.findViewById(R.id.tv_theme);
        tv_theme_title = view.findViewById(R.id.tv_theme_title);

        return view;
    }

    /**
     * 解決ScrollView 導致ListView 只顯示一項問題
     * @param listView
     */
    public static void setListViewHeightBasedOnChildren(ListView listView){
        NewsAdapter newsAdapter = (NewsAdapter) listView.getAdapter();
        if (newsAdapter==null){
            return;
        }
        int totalHeight=0;
        // newsAdapter.getCount() 獲取回傳資料項的數目
        for (int i=0;newsAdapter.getCount()>i;i++){
            View listItem = newsAdapter.getView(i,null,listView);
            // 計算子項View的寬高
            listItem.measure(0,0);
            // 統計所有子項的總高度
            totalHeight+=listItem.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalHeight+(listView.getDividerHeight()*(newsAdapter.getCount()-1));
        //getDividerHeight():獲取子項間分隔符占用的高度, params.height 得到整個ListView 完整顯示需要的高度
        listView.setLayoutParams(params);
    }

    @Override
    public void initData() {
        super.initData();
        initSearch();
        initBanner();
        getServiceData();
        getRecommendData();
        initNews();
    }

    // 頂部搜索框
    public void initSearch(){
        ed_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i== EditorInfo.IME_ACTION_SEARCH){
                    String search = ed_search.getText().toString();
                    Intent intent = new Intent(getActivity(), NewSearchActivity.class);
                    intent.putExtra("search",search);
                    startActivity(intent);
                    /*HomeFragment fragment = new HomeFragment();
                    Bundle bundle = new Bundle();
                    bundle.putString("search",search);
                    fragment.setArguments(bundle);
                    return fragment;*/
                }
                return false;
            }
        });
        tv_more.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("ResourceType")
            @Override
            public void onClick(View view) {
                Toast.makeText(getActivity(),"查看更多點擊底部進入",Toast.LENGTH_LONG).show();
            }
        });
        tv_theme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                /*Intent intent = new Intent(getActivity(), ServiceActivity.class);
                startActivity(intent);*/
                Toast.makeText(getActivity(),"更多主題點擊全部服務進入",Toast.LENGTH_LONG).show();
            }
        });
    }

    // Banner輪播圖
    public void initBanner(){
        //網路加載圖片
        List<BannerBean.RowsDTO> list = new ArrayList<>();
        list.add(new BannerBean.RowsDTO("http://124.93.196.45:10002/profile/home1.png", null));
        list.add(new BannerBean.RowsDTO("http://124.93.196.45:10002/profile/home2.png", null));
        list.add(new BannerBean.RowsDTO("http://124.93.196.45:10002/profile/home3.png", null));
        list.add(new BannerBean.RowsDTO("http://124.93.196.45:10002/profile/home4.png", null));
        banner.setAdapter(new BannerImageAdapter<BannerBean.RowsDTO>(list) {
            @Override
            public void onBindView(BannerImageHolder holder, BannerBean.RowsDTO data, int position, int size) {
                //BannerImageHolder 圖片加載自己實作
                Glide.with(getActivity())
                        .load(data.getImgUrl())
                        .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                        .into(holder.imageView);
            }
        }).addBannerLifecycleObserver(this)//添加生命周期觀察者
                .setIndicator(new CircleIndicator(getActivity()))
                .setOnBannerListener(new OnBannerListener() {
                    @Override
                    public void OnBannerClick(Object o, int position) {
                        //  getIntent(position);
                        Intent intent = new Intent(getActivity(), BannerWebView.class);
                        Bundle bundle = new Bundle();
                        bundle.putString("url",list.get(position).getImgUrl());
                        intent.putExtras(bundle);
                        getActivity().startActivity(intent);
                    }
                });
    }

    // 請求全部服務
    private void getServiceData() {
        Request request = new Request.Builder()
                .url(APIConfig.BASE_URL+"/service/service/list")
                .build();
        try {
            Call call = client.newCall(request);
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    Log.i("onFailure",e.getMessage());
                }
                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    if (response.isSuccessful()) {
                        final String result = response.body().string();
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Gson gson = new Gson();
                                ServiceBean serviceBean = gson.fromJson(result, ServiceBean.class);
                                Message msg = new Message();
                                msg.what=0;
                                msg.obj=serviceBean;
                                handler.sendMessage(msg);
                            }
                        });
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 主題推薦
    public void getRecommendData(){
        Request request = new Request.Builder()
                .url(APIConfig.BASE_URL+"/service/service/list?pageNum=1&pageSize=10")
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.i("onFailure",e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    final String recommend = response.body().string();
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Gson gson = new Gson();
                            RecommendBean recommendBean = gson.fromJson(recommend,RecommendBean.class);
                            Message msg = new Message();
                            msg.what=1;
                            msg.obj=recommendBean;
                            handler.sendMessage(msg);
                        }
                    });
                }
            }
        });
    }

    // 新聞資料
    public void initNews(){
        String[] title = {"時政","電視","旅游","視頻","廣播","基層"};
        List<Fragment> fragmentlist;
        fragmentlist = new ArrayList<>();
        fragmentlist.add(new NShizhengFragment());
        fragmentlist.add(new NTVFragment());
        fragmentlist.add(new NTravelFragment());
        fragmentlist.add(new NvideoFragment());
        fragmentlist.add(new NbrodcastFragment());
        fragmentlist.add(new NJicengFragment());
        getNewsData();
        newTabAdapter = new NewTabAdapter(getChildFragmentManager(),fragmentlist,title);
        newsAdapter = new NewsAdapter();
        view_pager.setAdapter(newTabAdapter);
        tab_layout.setupWithViewPager(view_pager);
    }

    // 新聞請求
    public void getNewsData(){
        Request request  = new Request.Builder()
                .url(APIConfig.BASE_URL+"/press/press/list")
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.i("onFailure",e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if (response.isSuccessful()) {
                    String result = response.body().string();
                    Log.i("請求成功",result);
                    Gson gson = new Gson();
                    newsBean =  gson.fromJson(result, NewsBean.class);
                    getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            home_listview.setAdapter(newsAdapter);
                            setListViewHeightBasedOnChildren(home_listview);
                            home_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                @Override
                                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                    Intent intent = new Intent(getActivity(), NewsWebViewActivity.class);
                                    ImageView new_img = view.findViewById(R.id.new_img);
                                    new_img.setDrawingCacheEnabled(Boolean.TRUE);
                                    intent.putExtra("bitmap",new_img.getDrawingCache());
                                    intent.putExtra("title",newsBean.getRows().get(i).getTitle());
                                    intent.putExtra("time",newsBean.getRows().get(i).getCreateTime());
                                    intent.putExtra("content",newsBean.getRows().get(i).getContent());
                                   /* Bundle bundle = new Bundle();
                                    bundle.putString("img",newsBean.getRows().get(i).getImgUrl());
                                    bundle.putString("title",newsBean.getRows().get(i).getTitle());
                                    bundle.putString("content",newsBean.getRows().get(i).getContent());
                                    bundle.putString("time",newsBean.getRows().get(i).getContent());
                                    intent.putExtras(bundle);*/
                                    getActivity().startActivity(intent);
                                }
                            });

                        }
                    });
                }
            }
        });
    }

    // 新聞配接器
    public class NewsAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return newsBean!=null ? newsBean.getRows().size() : 0;
        }
        @Override
        public Object getItem(int i) {
            return newsBean.getRows().get(i);
        }
        @Override
        public long getItemId(int i) {
            return i;
        }
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder holder;
            if (view==null) {
                view = View.inflate(getContext(), R.layout.news_item,null);
                holder = new ViewHolder();
                holder.new_title = view.findViewById(R.id.new_title);
                holder.new_context = view.findViewById(R.id.new_context);
                holder.new_create = view.findViewById(R.id.new_date);
                holder.likeNumber = view.findViewById(R.id.likeNumber);
                holder.viewsNumber = view.findViewById(R.id.viewsNumber);
                holder.new_img = view.findViewById(R.id.new_img);
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
            holder.likeNumber.setText(newsBean.getRows().get(i).getLikeNumber()+"");
            holder.viewsNumber.setText(newsBean.getRows().get(i).getViewsNumber()+"");
            holder.new_create.setText(newsBean.getRows().get(i).getCreateTime());
            holder.new_context.setText(newsBean.getRows().get(i).getContent());
            holder.new_title.setText(newsBean.getRows().get(i).getTitle());
            String url = APIConfig.BASE_URL+newsBean.getRows().get(i).getImgUrl();
            Glide.with(getActivity()).load(url).into(holder.new_img);
            return view;
        }
        class ViewHolder{
            TextView new_title;
            TextView new_context;
            TextView new_create;
            ImageView new_img;
            TextView viewsNumber;
            TextView likeNumber;
        }
    }
}

布局

在layout 目錄新建下面對應的xml檔案

fragment_home.xml:

在這里插入圖片描述

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#DFDFDF"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!--頂部搜索框-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:orientation="vertical"
        android:background="#1A5BDD">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="36dp"
            android:layout_marginLeft="24dp"
            android:layout_marginTop="11dp"
            android:layout_marginRight="24dp"
            android:background="@drawable/shape_search_box"
            android:gravity="center_horizontal"
            android:orientation="horizontal">
            <ImageView
                android:layout_width="22dp"
                android:layout_height="22dp"
                android:layout_marginLeft="13dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/home_search_icon"/>
            <EditText
                android:layout_marginLeft="4dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/ed_search"
                android:singleLine="true"
                android:imeOptions="actionSearch"
                android:background="@null"
                android:hint="搜索你想看的新聞"
                android:textColor="#000"
                android:textColorHint="#737373"/>
        </LinearLayout>
    </LinearLayout>
    <com.youth.banner.Banner
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:background="#BBD9F3"
        android:id="@+id/banner"/>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!--服務-->
            <androidx.recyclerview.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#B5D6F1"
                android:layout_margin="10dp"
                android:padding="10dp"
                android:id="@+id/home_recyclerview"/>

            <!--主題推薦-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/shape_login_form"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:orientation="horizontal">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="主題推薦"
                        android:gravity="left"
                        android:id="@+id/tv_theme_title"/>
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="熱門主題 >"
                        android:gravity="right"
                        android:id="@+id/tv_theme"/>
                </LinearLayout>
                <androidx.recyclerview.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#FFFFFF"
                    android:id="@+id/home_recyclerview1"/>
            </LinearLayout>

            <!--新聞-->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/shape_login_form"
                android:orientation="vertical">
                <TextView
                    android:layout_width="match_parent"
                    android:id="@+id/tv_more"
                    android:layout_height="wrap_content"
                    android:gravity="right"
                    android:text="查看更多 >"/>
                <com.google.android.material.tabs.TabLayout
                    android:layout_width="match_parent"
                    android:background="@drawable/shape_login_form"
                    app:tabGravity="fill"
                    app:tabMode="fixed"
                    app:tabTextColor="#121212"
                    app:tabIndicatorColor="#F8C221"
                    app:tabSelectedTextColor="#FFC107"
                    android:layout_height="wrap_content"
                    android:id="@+id/tab_layout"/>
                <androidx.viewpager.widget.ViewPager
                    android:id="@+id/view_pager"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:background="@drawable/shape_login_form"
                    android:layout_weight="1">
                </androidx.viewpager.widget.ViewPager>

                <ListView
                    android:layout_width="match_parent"
                    android:layout_marginTop="15dp"
                    android:layout_height="wrap_content"
                    android:id="@+id/home_listview"/>
            </LinearLayout>

        </LinearLayout>

    </ScrollView>

</LinearLayout>

service.item.xml:

在這里插入圖片描述

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_weight="1"
    android:layout_gravity="center"
    android:layout_marginTop="20dp"
    android:layout_height="wrap_content">
    <ImageView
        android:background="@drawable/category_shape"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_gravity="center"
        android:id="@+id/service_img"
        android:src="@mipmap/ic_launcher"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/service_name"
        android:textSize="20sp"
        android:textColor="#131313"
        android:layout_gravity="center"
        android:text="1111"
        />
</LinearLayout>

recommend_item.xml:

在這里插入圖片描述

news_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:background="@drawable/item_shape"
        android:orientation="horizontal">
        <ImageView
            android:id="@+id/new_img"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginRight="4dp"
            android:src="@mipmap/ic_launcher" />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginLeft="8dp"
                android:layout_weight="0.6"
                android:weightSum="1"
                android:orientation="horizontal">
                <TextView
                    android:id="@+id/new_title"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:textSize="20dp"
                    android:textColor="#5B4CB1"
                    android:text="我是titl"
                    android:gravity="center_vertical"
                    android:singleLine="true"/>
                <TextView
                    android:id="@+id/new_date"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="14dp"
                    android:layout_gravity="right"
                    android:text="2020-01-01"
                    android:layout_marginRight="0dp"
                    android:gravity="center_vertical"
                    android:singleLine="true"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_marginLeft="8dp"
                android:layout_weight="0.4"
                android:weightSum="1"
                android:orientation="horizontal">
                <TextView
                    android:id="@+id/new_context"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:textSize="14dp"
                    android:text="我是新聞內容,,,,,"
                    android:textColor="#5B4CB1"
                    android:gravity="center_vertical"
                    android:singleLine="true"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="22"
                    android:drawableLeft="@mipmap/like"
                    android:id="@+id/likeNumber"
                    android:layout_marginRight="6dp" />
                <TextView
                    android:text="333"
                    android:drawableLeft="@mipmap/browse"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/viewsNumber"/>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>
</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:padding="10dp"
    android:background="#0B7CF4"
    android:gravity="center"
    android:layout_height="wrap_content">

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@mipmap/ic_launcher"
        android:layout_gravity="center"
        android:id="@+id/theme_img"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="智慧醫療"
        android:gravity="center"
        android:textSize="20sp"
        android:textColor="#FFFFFF"
        android:id="@+id/theme_name"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="智慧巴士智慧巴士智慧巴士"
        android:gravity="center"
        android:textSize="16sp"
        android:textColor="#fff"
        android:id="@+id/theme_desc"/>

</LinearLayout>

配接器

在adapter目錄下新建下面對應adapter類:
在這里插入圖片描述

NewsAdapter

在adapter中新建NewsAdapter類,繼承baseAdapter,并重寫幾個方法:

package com.example.myapp.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.example.myapp.bean.NewsBean;
import com.example.myapp.R;
import com.example.myapp.utils.APIConfig;

import java.util.List;

/**
 * @ProjectName: MyApp4
 * @Package: com.example.myapp4.adapter
 * @ClassName: NewsAdapter
 * @Description:,
 * @Author: liyingxia
 * @CreateDate: 2021/3/31 9:20
 */
public class NewsAdapter extends BaseAdapter {
    private List<NewsBean.RowsBean> newsBean;
    private Context context;
    private List<Fragment> fragmentList;

    public NewsAdapter(List<NewsBean.RowsBean> newsBean,List<Fragment> fragmentList) {
        this.newsBean = newsBean;
        this.fragmentList = fragmentList;
    }

    @Override
    public int getCount() {
       // return newsBean!=null ? newsBean.getRows().size() : 0;
        return newsBean.size();
    }

    @Override
    public Object getItem(int i) {
        return newsBean.get(i);
    }

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

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view==null) {
            view = View.inflate(context, R.layout.news_item,null);
            holder = new ViewHolder();
            holder.new_title = view.findViewById(R.id.new_title);
            holder.new_context = view.findViewById(R.id.new_context);
            holder.new_create = view.findViewById(R.id.new_date);
            holder.likeNumber = view.findViewById(R.id.likeNumber);
            holder.viewsNumber = view.findViewById(R.id.viewsNumber);
            holder.new_img = view.findViewById(R.id.new_img);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.likeNumber.setText(newsBean.get(i).getLikeNumber());
        holder.viewsNumber.setText(newsBean.get(i).getViewsNumber());
        holder.new_create.setText(newsBean.get(i).getCreateTime());
        holder.new_context.setText(newsBean.get(i).getContent());
        holder.new_title.setText(newsBean.get(i).getTitle());
        String url = APIConfig.BASE_URL+newsBean.get(i).getImgUrl();
        Glide.with(context).load(url).into(holder.new_img);
        return view;
    }

    class ViewHolder{
        TextView new_title;
        TextView new_context;
        TextView new_create;
        ImageView new_img;
        TextView viewsNumber;
        TextView likeNumber;

    }
}

NewTabAdapter

這個是新聞分類標題配接器:

package com.example.myapp.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.List;

/**
 * @ProjectName: MyApp4
 * @Package: com.example.myapp4.adapter
 * @ClassName: NewTabAdapter
 * @Description:
 * @Author: liyingxia
 * @CreateDate: 2021/3/30 18:11
 */
public class NewTabAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragmentList;
    private String[] titles;

    public NewTabAdapter(@NonNull FragmentManager fm, List<Fragment> fragmentList, String[] titles) {
        super(fm);
        this.fragmentList = fragmentList;
        this.titles = titles;
    }


    /**
     * 回傳當前的fragment
     * @param position: 當前頁面的位置
     * @return
     */
    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    /**
     * fragment中的個數
     */
    @Override
    public int getCount() {
        return fragmentList.size();
    }

    /**
     * 回傳當前的標題
     */
    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}

RecommendAdapter

展示評論資料的配接器:

package com.example.myapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapp.R;
import com.example.myapp.bean.RecommendBean;
import com.example.myapp.utils.APIConfig;

import java.util.List;

/**
 * @ProjectName: MyApp4
 * @Package: com.example.myapp4.adapter
 * @ClassName: RecommendAdapter
 * @Description:
 * @Author: liyingxia
 * @CreateDate: 2021/4/5 15:58
 */
public class RecommendAdapter extends RecyclerView.Adapter<RecommendAdapter.MyViewHolder> {
private List<RecommendBean.RowsDTO> list;
private LayoutInflater layoutInflater;
private Context context;


// 3. 宣告介面
private OnItemClickListener mOnItemClickListener;

// 1. 定義介面
public interface OnItemClickListener{
    void onItemClick(int position, List<RecommendBean.RowsDTO> list);
}
// 2. 提供set方法給Activity/fragment呼叫
public void setOnItemClickListener(OnItemClickListener listener){
    mOnItemClickListener = listener;
}


    public RecommendAdapter(Context context,List<RecommendBean.RowsDTO> list) {
        this.list=list;
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.recommend_item,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.theme_name.setText(list.get(position).getServiceName());
        holder.theme_desc.setText(list.get(position).getServiceDesc());
        Glide.with(context).load(APIConfig.BASE_URL+list.get(position).getImgUrl()).into(holder.theme_img);
    }

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

    public class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView theme_name;
        private TextView theme_desc;
        private ImageView theme_img;

        public MyViewHolder(@NonNull View view) {
            super(view);
            this.theme_desc = view.findViewById(R.id.theme_desc);
            this.theme_name = view.findViewById(R.id.theme_name);
            this.theme_img = view.findViewById(R.id.theme_img);
            // 4. 將監聽傳遞給自定義介面
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (mOnItemClickListener!=null) {
                        mOnItemClickListener.onItemClick(getAdapterPosition(),list);
                    }
                }
            });
        }
    }
}

RecycleServiceAdapter

顯示服務資料的配接器:

package com.example.myapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapp.R;
import com.example.myapp.bean.ServiceBean;
import com.example.myapp.utils.APIConfig;

import java.util.List;

/**
 * @ProjectName: MyApp
 * @Package: com.example.myapp.adapter
 * @ClassName: RecycleServiceAdapter
 * @Description:
 * @Author: liyingxia
 * @CreateDate: 2021/4/23 10:05
 */
public class RecycleServiceAdapter extends RecyclerView.Adapter<RecycleServiceAdapter.MyViewHolder> {
    private LayoutInflater layoutInflater;
    private List<ServiceBean.RowsBean> rowsBeans;
    private Context context;
    private MyItemClickListener mItemClickListener;

    /**
     * 構造方法 傳入引數
     * @param context
     * @param rowsBeans
     */
    public RecycleServiceAdapter(Context context,List<ServiceBean.RowsBean> rowsBeans) {
        this.rowsBeans = rowsBeans;
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        // 創建ViewHolder, 回傳每一項的布局
        View view = layoutInflater.inflate(R.layout.service_item,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view,mItemClickListener);
        return myViewHolder;
    }

    // 將資料與控制元件系結
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.service_name.setText(rowsBeans.get(position).getServiceName());
        String url = APIConfig.BASE_URL + rowsBeans.get(position).getImgUrl();
        Glide.with(context).load(url).into(holder.service_img);
    }

    // 回傳Item總條數
    @Override
    public int getItemCount() {
        // return 10;
        return rowsBeans.size();
    }

    // 內部類,系結控制元件
    public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView service_name;
        private ImageView service_img;
        private MyItemClickListener myListener;

        public MyViewHolder(@NonNull View view,MyItemClickListener myItemClickListener) {
            super(view);
            this.myListener = myItemClickListener;
            itemView.setOnClickListener(this);
            service_img = view.findViewById(R.id.service_img);
            service_name = view.findViewById(R.id.service_name);
        }

        @Override
        public void onClick(View view) {
            if (myListener!=null) {
                myListener.onItemClick(view,getPosition());
            }
        }
    }

    //創建一個回呼介面
    public interface MyItemClickListener {
        void onItemClick(View view,int position);
    }
    //在activity中adapter中呼叫此方法,將點擊事件監聽傳遞過去,并賦值給全域監聽
    public void setItemClickListener(MyItemClickListener myItemClickListener){
        this.mItemClickListener = myItemClickListener;
    }

}

跳轉詳情頁面

關于點擊跳轉對應的Activity

在這里插入圖片描述

ApponitmentActivity,BusActivity,CityStateActivity,LivingPayActivity,ParkActivity,WeiZhangActivity等基本一致,后面需要填充什么內容自己實作,好吧~
這里只放一個:

CityStateAcivity:

package com.example.myapp.activity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.example.myapp.R;

public class CityStateActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private WebView webView;
    private String title;
    private TextView service_name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_city_state);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        webView = (WebView) findViewById(R.id.webView);
        service_name = findViewById(R.id.service_name);
        initData();
    }

    private void initData() {
        toolbar.setNavigationIcon(R.mipmap.top_bar_left_back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        Bundle bundle = new Bundle();
        bundle = getIntent().getExtras();
        String url = bundle.getString("url");
        title  = bundle.getString("title");
        service_name.setText(title);
        webView.loadUrl("/"+url);
        webView.requestFocusFromTouch();
        webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setJavaScriptEnabled(true);

    }
}

關于布局

在這里插入圖片描述

activity_apponitment,activity_bus,activity_weizhang,activity_city_state,activity_liviing_pay,activity_park等xml 檔案布局,這里也是基本都一樣

在這里插入圖片描述
這里只放其中一個:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".activity.BusActivity">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/toolbar"
            android:background="#0B84E4"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="違章查詢"
            android:textColor="#fff"
            android:id="@+id/service_name"
            android:textStyle="bold"
            android:textSize="20sp"
            android:gravity="center"
            android:layout_centerVertical="true"/>
    </RelativeLayout>
    <WebView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/webView"/>
</LinearLayout>

物體類

在bean目錄下新建如下:
在這里插入圖片描述

CommentBean:

package com.example.myapp.bean;

import java.util.List;

/**
 * @ProjectName: MyApp4
 * @Package: com.example.myapp4.bean
 * @ClassName: CommentBean
 * @Description:
 * @Author: liyingxia
 * @CreateDate: 2021/4/3 23:57
 */
public class CommentBean  {
    
    private int total;
    private int code;
    private String msg;
    private List<RowsDTO> rows;

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<RowsDTO> getRows() {
        return rows;
    }

    public void setRows(List<RowsDTO> rows) {
        this.rows = rows;
    }

    public static class RowsDTO {

        private String createTime;
        private Object updateBy;
        private ParamsDTO params;
        private String content;
        private String nickName;
        private String userName;
        private String avatar;


        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }

        public Object getUpdateBy() {
            return updateBy;
        }

        public void setUpdateBy(Object updateBy) {
            this.updateBy = updateBy;
        }


        public ParamsDTO getParams() {
            return params;
        }

        public void setParams(ParamsDTO params) {
            this.params = params;
        }

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public String getNickName() {
            return nickName;
        }

        public void setNickName(String nickName) {
            this.nickName = nickName;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getAvatar() {
            return avatar;
        }

        public void setAvatar(String avatar) {
            this.avatar = avatar;
        }

        public static class ParamsDTO {
        }

        @Override
        public String toString() {
            return "RowsDTO{" +
                    "createTime='" + createTime + '\'' +
                    ", content='" + content + '\'' +
                    ", nickName='" + nickName + '\'' +
                    ", userName='" + userName + '\'' +
                    ", avatar='" + avatar + '\'' +
                    '}';
        }

        public RowsDTO(String createTime, String content, String nickName, String userName, String avatar) {
            this.createTime = createTime;
            this.content = content;
            this.nickName = nickName;
            this.userName = userName;
            this.avatar = avatar;
        }
    }
}

RecommentBean:

package com.example.myapp.bean;

import java.util.List;

/**
 * @ProjectName: MyApp
 * @Package: com.example.myapp.bean
 * @ClassName: RecommendBean
 * @Description:
 * @Author: liyingxia
 * @CreateDate: 2021/4/5 9:18
 */
public class RecommendBean {


    private int total;
    private int code;
    private String msg;
    private List<RowsDTO> rows;

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<RowsDTO> getRows() {
        return rows;
    }

    public void setRows(List<RowsDTO> rows) {
        this.rows = rows;
    }
    public static class RowsDTO {
        /**
         * searchValue : null
         * createBy : null
         * createTime : 2020-10-12 18:17:23
         * updateBy : null
         * updateTime : 2020-10-19 16:56:47
         * remark : null
         * params : {}
         * id : 2
         * serviceName : 城市地鐵
         * serviceDesc : 城市地鐵路線
         * serviceType : 1
         * imgUrl : /profile/ditie.png
         * pid : 1
         * isRecommend : 1
         * link : metro_query/index
         */
        private String createTime;
        private String updateTime;
        private ParamsDTO params;
        private int id;
        private String serviceName;
        private String serviceDesc;
        private String serviceType;
        private String imgUrl;
        private int pid;
        private int isRecommend;
        private String link;


        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }

        public String getUpdateTime() {
            return updateTime;
        }

        public void setUpdateTime(String updateTime) {
            this.updateTime = updateTime;
        }

        public ParamsDTO getParams() {
            return params;
        }

        public void setParams(ParamsDTO params) {
            this.params = params;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getServiceName() {
            return serviceName;
        }

        public void setServiceName(String serviceName) {
            this.serviceName = serviceName;
        }

        public String getServiceDesc() {
            return serviceDesc;
        }

        public void setServiceDesc(String serviceDesc) {
            this.serviceDesc = serviceDesc;
        }

        public String getServiceType() {
            return serviceType;
        }

        public void setServiceType(String serviceType) {
            this.serviceType = serviceType;
        }

        public String getImgUrl() {
            return imgUrl;
        }

        public void setImgUrl(String imgUrl) {
            this.imgUrl = imgUrl;
        }

        public int getPid() {
            return pid;
        }

        public void setPid(int pid) {
            this.pid = pid;
        }

        public int getIsRecommend() {
            return isRecommend;
        }

        public void setIsRecommend(int isRecommend) {
            this.isRecommend = isRecommend;
        }

        public String getLink() {
            return link;
        }

        public void setLink(String link) {
            this.link = link;
        }


        public static class ParamsDTO {
        }
    }
}

ResponseBean:

package com.example.myapp.bean;

/**
 * @ProjectName: MyApp4
 * @Package: com.example.myapp4.bean
 * @ClassName: ResponseBean
 * @Description: 請求回應結果
 * @Author: liyingxia
 * @CreateDate: 2021/4/3 19:31
 */

public class ResponseBean {

    /**
     * msg : 操作成功
     * code : 200
     */

    private String msg;
    private String code;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "ResponseBean{" +
                "msg='" + msg + '\'' +
                ", code=" + code +
                '}';
    }
}

ServiceBean:

package com.example.myapp.bean;

import java.util.List;

/**
 * @ProjectName: MyApp
 * @Package: com.example.myapp.bean
 * @ClassName: ServiceBean
 * @Description:
 * @Author: liyingxia
 * @CreateDate: 2021/4/23 10:03
 */
public class ServiceBean {
    

    private int total;
    private int code;
    private String msg;
    private List<RowsBean> rows;

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<RowsBean> getRows() {
        return rows;
    }

    public void setRows(List<RowsBean> rows) {
        this.rows = rows;
    }

    public static class RowsBean {
        /**
         * searchValue : null
         * createBy : null
         * createTime : 2020-10-12 18:17:23
         * updateBy : null
         * updateTime : 2020-10-19 16:56:47
         * remark : null
         * params : {}
         * id : 2
         * serviceName : 城市地鐵
         * serviceDesc : 城市地鐵路線
         * serviceType : 1
         * imgUrl : /profile/ditie.png
         * pid : 1
         * isRecommend : 1
         * link : metro_query/index
         */

        private Object searchValue;
        private Object createBy;
        private String createTime;
        private Object updateBy;
        private String updateTime;
        private Object remark;
        private ParamsBean params;
        private int id;
        private String serviceName;
        private String serviceDesc;
        private String serviceType;
        private String imgUrl;
        private int pid;
        private int isRecommend;
        private String link;

        public Object getSearchValue() {
            return searchValue;
        }

        public void setSearchValue(Object searchValue) {
            this.searchValue = searchValue;
        }

        public Object getCreateBy() {
            return createBy;
        }

        public void setCreateBy(Object createBy) {
            this.createBy = createBy;
        }

        public String getCreateTime() {
            return createTime;
        }

        public void setCreateTime(String createTime) {
            this.createTime = createTime;
        }

        public Object getUpdateBy() {
            return updateBy;
        }

        public void setUpdateBy(Object updateBy) {
            this.updateBy = updateBy;
        }

        public String getUpdateTime() {
            return updateTime;
        }

        public void setUpdateTime(String updateTime) {
            this.updateTime = updateTime;
        }

        public Object getRemark() {
            return remark;
        }

        public void setRemark(Object remark) {
            this.remark = remark;
        }

        public ParamsBean getParams() {
            return params;
        }

        public void setParams(ParamsBean params) {
            this.params = params;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getServiceName() {
            return serviceName;
        }

        public void setServiceName(String serviceName) {
            this.serviceName = serviceName;
        }

        public String getServiceDesc() {
            return serviceDesc;
        }

        public void setServiceDesc(String serviceDesc) {
            this.serviceDesc = serviceDesc;
        }

        public String getServiceType() {
            return serviceType;
        }

        public void setServiceType(String serviceType) {
            this.serviceType = serviceType;
        }

        public String getImgUrl() {
            return imgUrl;
        }

        public void setImgUrl(String imgUrl) {
            this.imgUrl = imgUrl;
        }

        public int getPid() {
            return pid;
        }

        public void setPid(int pid) {
            this.pid = pid;
        }

        public int getIsRecommend() {
            return isRecommend;
        }

        public void setIsRecommend(int isRecommend) {
            this.isRecommend = isRecommend;
        }

        public String getLink() {
            return link;
        }

        public void setLink(String link) {
            this.link = link;
        }

        public static class ParamsBean {
        }

        public RowsBean(String serviceName, String serviceDesc, String imgUrl, String link) {
            this.serviceName = serviceName;
            this.serviceDesc = serviceDesc;
            this.imgUrl = imgUrl;
            this.link = link;
        }

        @Override
        public String toString() {
            return "RowsBean{" +
                    "serviceName='" + serviceName + '\'' +
                    ", serviceDesc='" + serviceDesc + '\'' +
                    ", imgUrl='" + imgUrl + '\'' +
                    ", link='" + link + '\'' +
                    '}';
        }
    }
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/280723.html

標籤:其他

上一篇:PAT乙級 1011 A+B 和 C (15 分)

下一篇:vue3.0 + vite (一)頁面渲染

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more