如何在导航抽屉Recyclers视图点击事件中设置getSupportFragmentManager
。
public class DrawerListAdapter extends RecyclerView.Adapter<DrawerListAdapter.DrawerViewHolder> {
private Context context;
private Activity activity;
private LayoutInflater inflater;
List<info> data = Collections.emptyList();
private FragmentManager mFragmentManager;
public DrawerListAdapter(FragmentManager fm) {
mFragmentManager = fm;
}
public DrawerListAdapter(Context contex, List<info> data) {
inflater = LayoutInflater.from(context);
this.data = data;
this.context = contex;
}
@Override
public DrawerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.custome_row, parent, false);
DrawerViewHolder holder = new DrawerViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(DrawerViewHolder holder, int position) {
info current = data.get(position);
holder.title.setText(current.title);
holder.icon.setImageResource(current.iconId);
}
@Override
public int getItemCount() {
return data.size();
}
static class DrawerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView title;
ImageView icon;
// private ClickListener clickListener;
public DrawerViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.text_title);
icon = (ImageView) itemView.findViewById(R.id.imageView);
title.setOnClickListener(this);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
Log.d("RecyclerView", "onClick:" + getPosition());
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, Fragment_home.newInstance(),
Fragment_home.TAG).commit();
}
}
}