为什么我要为这个linearlayout获取一个空值

0qx6xfy6  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(268)

我正在更新这个 LinearLayout 但我得到了一个 null 价值观。有人能告诉我为什么吗?
java 语:

public class MenuTabFragment extends Fragment {

    private final static String TAG = MenuTabFragment.class.getSimpleName();

    private int[] menuButtons = { R.drawable.breakfast_btn,
            R.drawable.lunch_btn, R.drawable.dinner_btn, R.drawable.drinks_btn,
            R.drawable.appetizers_btn, R.drawable.dessert_btn,
            R.drawable.sides_btn };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.menutabslayout, container, false);
            //this is a null value
        LinearLayout linLayout = (LinearLayout) getActivity().findViewById(R.id.menuTabs);
        Log.i(TAG, linLayout + ": linLayout" );

xml格式:

<LinearLayout
    android:id="@+id/menuTabs"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
</LinearLayout>
l3zydbqr

l3zydbqr1#

尝试 LinearLayout linLayout = (LinearLayout) view.findViewById(R.id.menuTabs);

相关问题