Search in sources :

Example 1 with TabContentFactory

use of android.widget.TabHost.TabContentFactory in project robolectric by robolectric.

the class ShadowTabSpecTest method shouldSetTheContentView.

@Test
public void shouldSetTheContentView() throws Exception {
    TabHost.TabSpec foo = new TabHost(RuntimeEnvironment.application).newTabSpec("Foo").setContent(new TabContentFactory() {

        public View createTabContent(String tag) {
            TextView tv = new TextView(RuntimeEnvironment.application);
            tv.setText("The Text of " + tag);
            return tv;
        }
    });
    ShadowTabHost.ShadowTabSpec shadowFoo = shadowOf(foo);
    TextView textView = (TextView) shadowFoo.getContentView();
    assertThat(textView.getText().toString()).isEqualTo("The Text of Foo");
}
Also used : TabHost(android.widget.TabHost) TabContentFactory(android.widget.TabHost.TabContentFactory) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test)

Example 2 with TabContentFactory

use of android.widget.TabHost.TabContentFactory in project robolectric by robolectric.

the class ShadowTabHostTest method shouldRetrieveTheCurrentViewFromTabContentFactory.

@Test
public void shouldRetrieveTheCurrentViewFromTabContentFactory() {
    TabHost tabHost = new TabHost(RuntimeEnvironment.application);
    TabHost.TabSpec foo = tabHost.newTabSpec("Foo").setContent(new TabContentFactory() {

        public View createTabContent(String tag) {
            TextView tv = new TextView(RuntimeEnvironment.application);
            tv.setText("The Text of " + tag);
            return tv;
        }
    });
    tabHost.addTab(foo);
    tabHost.setCurrentTabByTag("Foo");
    TextView textView = (TextView) tabHost.getCurrentView();
    assertThat(textView.getText().toString()).isEqualTo("The Text of Foo");
}
Also used : TabHost(android.widget.TabHost) TabContentFactory(android.widget.TabHost.TabContentFactory) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test)

Aggregations

View (android.view.View)2 TabHost (android.widget.TabHost)2 TabContentFactory (android.widget.TabHost.TabContentFactory)2 TextView (android.widget.TextView)2 Test (org.junit.Test)2