为什么我为此linearlayout获取空值

时间:2012-08-24 16:04:35

标签: java android

我正在尝试更新此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>

1 个答案:

答案 0 :(得分:5)

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