开发者

Android Programming Tutorials: #6

开发者 https://www.devze.com 2022-12-16 23:40 出处:网络
I started working through the tutorials in Mark L Murphy\'s book \"Android Progra开发者_运维技巧mming Tutorials\". In Tutorial #6, they are starting to work with tabs. I copied the code:

I started working through the tutorials in Mark L Murphy's book "Android Progra开发者_运维技巧mming Tutorials". In Tutorial #6, they are starting to work with tabs. I copied the code:

    TabHost.TabSpec spec=getTabHost().newTabSpec("tag1");

    spec.setContent(R.id.restaurants);
    spec.setIndicator("List", getResources()
    .getDrawable(R.drawable.list));
    getTabHost().addTab(spec);

    spec=getTabHost().newTabSpec("tag2");
    spec.setContent(R.id.details);
    spec.setIndicator("Details", getResources()
    .getDrawable(R.drawable.restaurant));
    getTabHost().addTab(spec);

    getTabHost().setCurrentTab(0);

into my application, and got syntax errors on "getTabHost". I am using

import android.app.Activity;
import android.app.ActivityGroup;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

How do I clear the "The method getTabHost() is undefined for the type ListerApp" error? Am I missing an import?


Does your class extend TabActivity or Activity? I think it will need to extend TabActivity.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号