【问题标题】:Implententing a swipe view using a Fragment使用片段实现滑动视图
【发布时间】:2016-06-29 10:37:41
【问题描述】:

我正在设计一个宪法应用程序,我想使用带有滑动视图的选项卡式布局。选项卡使用自定义适配器从数据库中获取数据。由于数据大小(片段数量)未知,我希望每次滑动都能生成一个新视图,这些视图是宪法中不同的章节内容。

我想要一些看起来像下面的字典应用程序的东西,两边都有滑动标签。我熟悉标签,但我很想获得一个资源来帮助我实现这一点,因为我见过的大多数文档都没有解释这一点。谢谢

【问题讨论】:

  • 寻找浏览器
  • 它只是一个浏览器。您可以在视图寻呼机的帮助下实现所需的输出。

标签: android swipe android-tablayout uiswipegesturerecognizer swipe-gesture


【解决方案1】:

用你想要的输出修改它

onCreate

 ArrayList<McqQuestionBean> mcqQuestionBeans= new ArrayList<McqQuestionBean>();
        adapter = new NewsFragmentPagerAdapter(getSupportFragmentManager(),
                mcqQuestionBeans, MCQTestActivity.this);
        pager.setAdapter(adapter);

基础适配器

public class NewsFragmentPagerAdapter extends FragmentStatePagerAdapter {

private ArrayList<McqQuestionBean> mcqQuestionBeans;

private McqQuestionFragment fragment;
private Activity context;

public NewsFragmentPagerAdapter(FragmentManager fm, ArrayList<McqQuestionBean> mcqQuestionBeans, Activity context) {
    super(fm);
    this.mcqQuestionBeans = mcqQuestionBeans;

    this.context = context;

}

public void update(ArrayList<McqQuestionBean> mcqQuestionBeans) {
    this.mcqQuestionBeans = mcqQuestionBeans;
    notifyDataSetChanged();
}

@Override
public int getCount() {
    return mcqQuestionBeans.size();
}

@Override
public int getItemPosition(Object object) {
    // TODO Auto-generated method stub
    return super.getItemPosition(object);
}

@Override
public Fragment getItem(int position) {

    fragment = McqQuestionFragment.newInstance(mcqQuestionBeans.get(position), position, context);

    return fragment;

}

}

你的片段 McqQuestionFragment

public class McqQuestionFragment extends Fragment {

private int position, porrefid;
    private String question;
    private ArrayList<McqQuestionChoiceBean> choices;   



@SuppressWarnings("unchecked")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        position = getArguments().getInt("position");
        porrefid = getArguments().getInt("porrefid");
        userMarkedOn = getArguments().getInt("userMarkedOn");
        question = getArguments().getString("question");
        choices = (ArrayList<McqQuestionChoiceBean>) getArguments()
                .getSerializable("choices");
    }

    public static McqQuestionFragment newInstance(
            McqQuestionBean mcqQuestionBean, int position, Activity activity) {
        final McqQuestionFragment f = new McqQuestionFragment();
        final Bundle args = new Bundle();
        args.putString("question", mcqQuestionBean.getQuestion());
        args.putInt("position", position);
        args.putInt("userMarkedOn", mcqQuestionBean.getUserCorrectedOn());
        args.putSerializable("choices", mcqQuestionBean.getChoices());
        args.putInt("porrefid", mcqQuestionBean.getPorrefid());
        f.setArguments(args);

        return f;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多