GT package that you can't put down in development. Follow the GSLS official website to view more source code (✿ ゚ ▽ ゚) toolkit.
All articles are compiled so that readers can directly read and completely copy and paste. Among them, complex or more source codes will have source codes and paste them on the github website.
The source code in GT class is completely open source, with more Chinese comments, so that more people can read it directly.
Click a point of interest and a praise (″ '▽' ″), and pay attention to the latest release Library of the blogger: https://github.com/1079374315/GSLS_Tool
Meidi framework makes creation so simple!
Previous chapter: Fragment novice teaching Chapter 1 framework characteristics
Some time ago, it made the GT library a bigger wave, and the biggest change was GT_Fragment is a class, and all the code in this class is reconstructed once.
Next, let's take a look at how to create a simple Fragment using the GT library
Step 1: Rely on the latest GT Library
Step 2: there are two types of Fragment auxiliary classes in the GT library. One is the base class named BaseFragments, and the other is the annotation Fragment auxiliary class created with annotations. Let's take a look at the differences between the two created Fragment base classes.
The first is to create a simple Fragment using {BaseFragments
//Create fragments by inheriting the BaseFragments class public class Fragment_A extends GT.GT_Fragment.BaseFragments { @Override protected int loadLayout() { return R.layout.fragment_a;//Load layout } @Override protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) { //Initialize UI } @Override protected void loadData() { super.loadData(); //Business logic processing } }
Corresponding {fragment_a XML layout:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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:background="#EF8B8B" > </androidx.constraintlayout.widget.ConstraintLayout>
Create a Fragment using BaseFragment class. The steps are as follows:
(1) inherit the auxiliary class gt.gt_fragments.basefragments from the GT library.
(2) Rewrite the method of loading layout {protected int loadLayout() and return the layout file to be loaded.
(3) Rewrite the protected void initView() method of the initialization component
(4) Rewrite the protected void loadData() method of loading data
After these four steps, a simple Fragment is created. It's very simple.
The second is to create a simple Fragment by using {annotation Fragment
//Create a Fragment by inheriting the AnnotationFragment class @GT.Annotations.GT_AnnotationFragment(R.layout.fragment_b) //Load layout public class Fragment_B extends GT.GT_Fragment.AnnotationFragment { @Override protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) { //Initialize UI } @Override protected void loadData() { super.loadData(); //Business logic processing } }
Corresponding {fragment_b XML layout:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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:background="#70B2CF" > </androidx.constraintlayout.widget.ConstraintLayout>
Create a Fragment using the AnnotationFragment} class. The steps are as follows:
(1) inherit the # GT.GT_Fragment.AnnotationFragment # auxiliary class from the GT library.
(2) write the layout file in the annotation of the Fragment class.
(3) Rewrite the protected void initView() method of the initialization component
After these three steps, a simple Fragment will be created. This is simpler.
Next chapter: Android - Fragment Chapter 3 uses the created Fragment (inheritance chapter)
It will be updated after optimization
Thank you for your attention