Simply trying to change the text on the tabs for android app. Who knew it would be this much trouble. how to resolve 'cannot be resolved' & 'cannot be resolved or is not a field' errors for mTabHost, tabs_bg and tabsText
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class Tabs extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
setupTab(new TextView(this), "List");
setupTab(new TextView(this), "Map");
}
private void setupTab(final View view, final String tag) {
View tabview = createTabViewe(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {return view;}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tabs, menu);
return true;
}
}
You need to declare mTabHost
TabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
tabs_bg
is a layout. Do you have tabs_bg.xml
in your layout folder. Also you need to check if you have a textview with id tabsText
in tabs_bg.xml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.