parent
eb80cb2935
commit
06fe27021b
@ -0,0 +1,40 @@
|
||||
package com.android.activity.adapter;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import com.android.activity.fragment.GoodsTypeFragment;
|
||||
import com.android.bean.Goods;
|
||||
import com.android.bean.GoodsType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GoodsTypeFSAdapter extends FragmentStateAdapter{
|
||||
private List<GoodsType> goodsTypeList;
|
||||
private List<Fragment> fragmentList;
|
||||
|
||||
public GoodsTypeFSAdapter(@NonNull FragmentManager fragmentManager,
|
||||
@NonNull Lifecycle lifecycle,
|
||||
// List<GoodsType> goodsTypeList, List<Goods> goodsList,
|
||||
List<Fragment> fragmentList){
|
||||
super(fragmentManager, lifecycle);
|
||||
this.fragmentList = fragmentList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
|
||||
return fragmentList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return fragmentList.size();
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.android.activity.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link GoodsTypeFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class GoodsTypeFragment extends Fragment {
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_TEXT = "param1";
|
||||
|
||||
View rootView;
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
|
||||
public GoodsTypeFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @return A new instance of fragment GoodsTypeFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static GoodsTypeFragment newInstance(String param1) {
|
||||
GoodsTypeFragment fragment = new GoodsTypeFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_TEXT, param1);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
|
||||
if(rootView == null)
|
||||
rootView = inflater.inflate(R.layout.fragment_goods_type, container, false);
|
||||
initView();
|
||||
return rootView;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
TextView view = rootView.findViewById(R.id.tv_goods);
|
||||
view.setText(mParam1);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.fragment.GoodsTypeFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:id="@+id/tv_goods"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
|
||||
</FrameLayout>
|
@ -1,15 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.fragment.HomePageFragment">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/lv_goodsType_list"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tabLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:isScrollContainer="true"/>
|
||||
app:tabMode="scrollable"
|
||||
/>
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue