gpt4 book ai didi

android - 我可以将 View 寻呼机与 View 一起使用(而不是 fragment )

转载 作者:IT老高 更新时间:2023-10-28 12:59:40 25 4
gpt4 key购买 nike

我正在使用 ViewPagerFragments 之间滑动,但是我可以使用 ViewPagerViews 之间滑动吗? XML 布局?

这是我的页面 Adapter 用于在 Fragments 之间滑动的 ViewPager:

import java.util.List;

import com.app.name.fragments.TipsFragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.view.ViewGroup;

public class PageAdapter extends FragmentPagerAdapter {

/**
*
*/
List<Fragment> fragments;
public PageAdapter(FragmentManager fm,List<Fragment> frags) {
super(fm);
fragments = frags;

}

@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return TipsFragment.newInstance(0, 0);
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return 4;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
FragmentManager manager = ((Fragment) object).getFragmentManager();
FragmentTransaction trans = manager.beginTransaction();
trans.remove((Fragment) object);
trans.commit();

super.destroyItem(container, position, object);
}

}

这是我的提示 fragment :

public class TipsFragment extends Fragment
{
public static TipsFragment newInstance(int image,int content)
{
TipsFragment fragment = new TipsFragment();
return fragment;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tip_layout, null);
return view;
}
}

如何修改我的代码以使用 View 而不是 fragment ?

最佳答案

你需要重写这两个方法而不是getItem():

@Override
public Object instantiateItem(ViewGroup collection, int position) {
View v = layoutInflater.inflate(...);
...
collection.addView(v,0);
return v;
}

@Override
public void destroyItem(ViewGroup collection, int position, Object view) {
collection.removeView((View) view);
}

关于android - 我可以将 View 寻呼机与 View 一起使用(而不是 fragment ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18710561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com