0

我已经使用了操作栏,它工作正常。我在操作栏中有四个片段。我想在其中一个片段中实现 tabhost。我使用了以下代码。

    package com.main.udebate;

import android.support.v4.app.Fragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class Info extends Fragment {
    public Info() {
    }

    public static final String ARG_SECTION_NUMBER = "section_number";
    private TabHost mTabHost;

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

        Intent i = new Intent(Info.this, about.class);

         View view = inflater.inflate(R.layout.info, container, false);
         mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
         mTabHost.setup();

        TabHost.TabSpec tab = mTabHost.newTabSpec("my tab content");
        tab.setIndicator("my tab content");
        tab.setContent(i);
        mTabHost.addTab(tab);
        mTabHost = (TabHost) view.findViewById(android.R.id.tabhost);
        return view;

    }
}

Intent i = new Intent(Info.this, about.class);由于构造函数 Intent(Info, Class) 未定义,我在线收到错误。

关于.java

  package com.main.udebate;

import android.app.Activity;
import android.os.Bundle;

public class about extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
    }
}

有人可以帮我在片段中设置tabhost。

谢谢,

4

1 回答 1

1

尝试使用这个

Intent i = new Intent(getActivity(), about.class); 

而不是这条线

Intent i = new Intent(Info.this, about.class);

由于 Info.this 并不意味着任何上下文,这就是为什么您会得到“构造函数 Intent(Info, Class) 未定义”。这个错误。

在您使用参考的片段中,this您应该使用getActivity()参考

于 2013-11-19T14:58:38.223 回答