我有三个viewpager标签,即问题,文章和视频。我想进入标签页并在问题标签上加载一些数据
@Override
public void onBindViewHolder(final RecyclerViewHolder holder, int position) {
i=position;
String url="https://d1v0zurmr84n8z.cloudfront.net/";
String value=notificationList.get(position).getIs_pic();
holder.name.setText("Raised by:"+notificationList.get(position).getGenerated_by_name());
holder.type.setText("Type:"+notificationList.get(position).getNotification_type());
holder.date.setText("Date:"+notificationList.get(position).getTime());
holder.visit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String classId=notificationList.get(i).getClass_id();
getRetrofit(classId);
/*----i have tried this but this is showing error....R.id.content_classroom is not a vlaid argument
QuestionFragment qf=new QuestionFragment();
FragmentManager fm = ((Home)context).getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.content_classroom, qf);
ft.commit();
*/}
});
这些是在标签中加载的片段
public void setupViewPager(ViewPager viewPager) {
MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new QuestionFragment(), FRAGMENT_NAME[0]);
adapter.addFragment(new ArticleFragment(), FRAGMENT_NAME[1]);
adapter.addFragment(new VideoFragment(), FRAGMENT_NAME[2]);
//Set adapter to ViewPager
viewPager.setAdapter(adapter);
}
答案 0 :(得分:2)
在method
fragment
public void selectTab(int position) {
mViewPager.setCurrentItem(position);
}
调用此方法选择选项卡。
问题 - 位置0
,文章 - 位置1
和视频 - 位置2
----从recyclerView
召唤方法----
制作适配器类abstract
public abstract class CartAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
// constructor ..
// Other recyclerView methods
// You ViewHolder class
public class CartHolder extends RecyclerView.ViewHolder {
Button mButton;
CartHolder(View itemView) {
super(itemView);
mButton = (Button) itemView.findViewById(R.id.referece_of_view);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OnButtonClicked();
}
});
}
}
protected abstract void OnButtonClicked();
}
初始化适配器时,
mAdapter = new CartAdapter(context, mDataSet) {
@Override
protected void OnButtonClicked() {
// Call method selectTab()
}
};