0

我正在設計一個構成應用程序,我想在滑動視圖中使用選項卡式佈局。這些選項卡使用自定義適配器從數據庫中獲取數據。由於數據大小(片段號)未知,因此我希望每次滑動都能生成一個新視圖,這是憲法中不同的章節內容。使用片段執行滑動視圖

我想要看起來像下面的字典應用程序,兩邊刷卡標籤的東西。我對標籤很熟悉,但我很樂意獲得資源來幫助我實現這一目標,因爲我見過的大多數文檔都沒有解釋這一點。由於

enter image description here

+0

尋找viewpager – Nisarg

+0

它只是一個viewpager。你可以在視圖尋呼機的幫助下實現你想要的輸出。 –

回答

0

與所需輸出修改此

的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; 
    } 

}