好的,我有一个片段,我想在它的xml文件中包含另一个通过编程膨胀的布局。
片段:
XML文件片段的翻译:
我想在上面的XML中以编程方式包含一个XML布局:
我尝试了几种不同的方法,但都导致了“在空对象引用上”的错误...请帮忙:)
片段:
public class zGoal_Fragment extends Fragment{
private LinearLayout todayView;
private View view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.main_goal_view, container, false);
todayView = (LinearLayout)view.findViewById(R.id.todayView);
return view;
}
}
XML文件片段的翻译:
xml文件片段:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/todayView"
>
</LinearLayout>
我想在上面的XML中以编程方式包含一个XML布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/goalEditLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/test_color_two"
>
</LinearLayout>
我尝试了几种不同的方法,但都导致了“在空对象引用上”的错误...请帮忙:)