滑动解析镜面Fragment
Posted xiaxinxin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了滑动解析镜面Fragment相关的知识,希望对你有一定的参考价值。
public class Fra extends Fragment{
private List<Study.NewslistBean>list=new ArrayList<>();
private int num=0;
private String urldaty="http://api.tianapi.com/guonei/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num=10"+num;
private PullToRefreshListView lv1;
private TextView tv;
private MyAdapter2 myAdapter2;
private int type=1;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fraview,container,false);
lv1= view.findViewById(R.id.lv1);
tv = view.findViewById(R.id.tv);
Bundle arguments=getArguments();
String data=arguments.getString("data");
intoptlv();
getdatas();
return view;
}
private void getdatas(){
MyTask myTask=new MyTask(new MyTask.Icallbacks() {
@Override
public void updateUiByjson(String jsonstr) {
Gson gson=new Gson();
Study study = gson.fromJson(jsonstr, Study.class);
List<Study.NewslistBean> newslist = study.getNewslist();
if (type==1){
list.clear();
}
list.addAll(newslist);
setplvAdp();
}
});
myTask.execute(urldaty);
lv1.onRefreshComplete();
}
private void setplvAdp(){
if (myAdapter2==null){
new MyAdapter2(getActivity(),list);
lv1.setAdapter(myAdapter2);
}else {
myAdapter2.notifyDataSetChanged();
}
}
private void intoptlv(){
lv1.setMode(PullToRefreshBase.Mode.BOTH);
lv1.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
type=1;
num=0;
urldaty="http://api.tianapi.com/huabian/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num="+num;
getdatas();
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
type=2;
num++;
urldaty="http://api.tianapi.com/huabian/?key=48a7d7193e11bd2dd4a683b6e2f90a4f&num="+num;
getdatas();
}
});
}
}
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv"/>
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:layout_width="match_parent"
android:layout_height="match_parent"
ptr:ptrDrawable="@drawable/default_ptr_flip"
ptr:ptrAnimationStyle="flip"
ptr:ptrHeaderBackground="#383838"
android:id="@+id/lv1"
ptr:ptrHeaderTextColor="#FFFFFF"></com.handmark.pulltorefresh.library.PullToRefreshListView>
public class Fragment03 extends Fragment {
private ViewPager vp;
private TabLayout tl;
private List<String> tabMenu;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment03, container, false);
vp = view.findViewById(R.id.vp);
tl = view.findViewById(R.id.tl);
getData();
vp.setAdapter(new MyAdapter(getChildFragmentManager()));
tl.setupWithViewPager(vp);
return view;
}
private void getData() {
tabMenu = new ArrayList<>();
tabMenu.add("推荐");
tabMenu.add("玄幻");
tabMenu.add("都市");
tabMenu.add("修仙");
tabMenu.add("言情");
}
class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return tabMenu.size();
}
@Override
public CharSequence getPageTitle(int position) {
return tabMenu.get(position);
}
@Override
public Fragment getItem(int position) {
Fra fra = new Fra();
Bundle bundle = new Bundle();
bundle.putString("data", tabMenu.get(position));
fra.setArguments(bundle);
return fra;
}
}
}
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/tl"
app:tabMaxWidth="0dp"
app:tabIndicatorColor="#fff"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorPrimary"
app:tabTextColor="@color/colorPrimary"></android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vp"
android:layout_below="@id/tl"></android.support.v4.view.ViewPager>
以上是关于滑动解析镜面Fragment的主要内容,如果未能解决你的问题,请参考以下文章