Я решил использовать представления для моего интерфейса вкладки ...
Я следую учебному пособию по интерфейсу вкладок, и результатом этого учебного пособия являются 4 вкладки без содержимого (текста) под моими вкладками.
Мне было интересно, как работают представления ... как я могу создать метод для установки содержимого на вкладку из другого класса ... Так что main.java - это мой основной файл с представлениями (вкладками). Tab1.java имеет код навигации по Google Maps.
Как я могу вызвать метод setupTab и установить функцию навигации на вкладку 1.
Здесь вы можете увидеть мой код:
Заранее спасибо!
package CustomTabs;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
public class CustomTabs extends Activity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// construct the tabhost
setContentView(R.layout.main);
setupTabHost();
setupTab(new TextView(this), "Tab 1", getResources().getDrawable(R.drawable.ic_tab_artists));
setupTab(new TextView(this), "Tab 2", getResources().getDrawable(R.drawable.ic_tab_artists));
setupTab(new TextView(this), "Tab 3", getResources().getDrawable(R.drawable.ic_tab_artists));
setupTab(new TextView(this), "Tab 4", getResources().getDrawable(R.drawable.ic_tab_artists));
{
final View v = mTabHost.getTabWidget().getChildAt(0);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
{
final View v = mTabHost.getTabWidget().getChildAt(1);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
{
final View v = mTabHost.getTabWidget().getChildAt(2);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
{
final View v = mTabHost.getTabWidget().getChildAt(3);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
}
private void setupTab(final View view, final String tag, Drawable icon) {
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tag, icon).setContent(new TabContentFactory() {
public View createTabContent(String tag) {return view;}
});
mTabHost.addTab(setContent);
}
}