我有childblog.xml
<TextView
android:id="@+id/tv_fab1"
adroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:text="Google+"
android:textColor="@color/white"
android:textSize="16dp"
/>
我有适配器类,它为循环视图中的每个项目膨胀上面的childblog布局。
@Override
public Holder_blog onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.child_blog, parent, false);
Holder_blog holder_blog = new Holder_blog(view);
return holder_blog;
}
我正在尝试在我的片段中引用childblog的textview,其中包含了recycleview
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_blog, container, false);
System.out.println("Current Class===>>>" + getClass().getSimpleName());
((MainActivity) getActivity()).enable_imv_drawer_mainactivity();
tv_fab1 = (TextView) container.findViewById(R.id.tv_fab1);
我得到了一个空对象引用。如何在片段中获取childblog的textview。
答案 0 :(得分:0)
更改
tv_fab1 = (TextView) container.findViewById(R.id.tv_fab1);
到
tv_fab1 = (TextView) view.findViewById(R.id.tv_fab1);