Java 如何以编程方式创建包含EditText的选项卡?
我的应用程序的文本编辑器允许用户打开和编辑文件,我想在TabHost中将文件作为新选项卡打开,以便可以打开多个文件。如何将EditText添加到新创建的选项卡?这是我在onCreate()中尝试的内容 我假设问题是'spec1.setContent(editor.getId()) 您尝试将一个id(未按方式定义)设置为布局id。 那样不行。尝试:Java 如何以编程方式创建包含EditText的选项卡?,java,android,android-tabhost,Java,Android,Android Tabhost,我的应用程序的文本编辑器允许用户打开和编辑文件,我想在TabHost中将文件作为新选项卡打开,以便可以打开多个文件。如何将EditText添加到新创建的选项卡?这是我在onCreate()中尝试的内容 我假设问题是'spec1.setContent(editor.getId()) 您尝试将一个id(未按方式定义)设置为布局id。 那样不行。尝试: TabHost tabHost=(TabHost)findViewById(R.id.tabHost); tabHost.setup(
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
EditText editor = new EditText(this);
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setIndicator(editor);
如果这是你想要的。您也可以尝试:
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
final EditText editor = new EditText(this);
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(new TabHost.TabContentFactory(){
public View createTabContent(String tag){
return editor;
}
});
你能发布你的
xml
?xml不相关(我不这么认为:)试着回答Rafael。1秒
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
final EditText editor = new EditText(this);
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(new TabHost.TabContentFactory(){
public View createTabContent(String tag){
return editor;
}
});