1

I started working through the tutorials in Mark L Murphy's book "Android Programming 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?

jball
25.1k9 gold badges73 silver badges92 bronze badges
asked Jan 21, 2010 at 21:44

1 Answer 1

6

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

answered Jan 21, 2010 at 21:46
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you!!!! forehead_slap! I have stared at that thing for hours, trying to figure out which widget i missed.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.