开发者

TabView in android

开发者 https://www.devze.com 2023-03-14 05:44 出处:网络
I have three tabs, the content of each tab is a view ( Gridview in this case). I have created an image adapter class to populate the grid.

I have three tabs, the content of each tab is a view ( Gridview in this case). I have created an image adapter class to populate the grid. I call the Image adapter using

GridView gridview=(GridView)findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));

But each view must be populated differently. How do i know which view called the image adapter class? Is there a method a to pass 开发者_运维问答an argument along with the call or can this be done differently?


Try creating a constructor in your grid adapter class, and try to pass the array along with the context


Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost

    Intent intent = new Intent(this, a0.class);
    tabHost.addTab(tabHost.newTabSpec("")
            .setIndicator("", res.getDrawable(R.drawable.ic_tab_main))
            .setContent(intent));

    Intent intent2 = new Intent(this, c0.class);
    tabHost.addTab(tabHost
            .newTabSpec("")
            .setIndicator("", res.getDrawable(R.drawable.ic_tab_setup))
            .setContent(intent2));

    Intent intent3 = new Intent(this, d0.class);
    tabHost.addTab(tabHost
            .newTabSpec("")
            .setIndicator("", res.getDrawable(R.drawable.ic_tab_third))
            .setContent(intent3));
    Intent intent4 = new Intent(this, e0.class);
    tabHost.addTab(tabHost
            .newTabSpec("")
            .setIndicator("", res.getDrawable(R.drawable.ic_tab_setting))
            .setContent(intent4));

    tabHost.setCurrentTab(0);

    // Set tabs Colors
    tabHost.setBackgroundColor(Color.BLACK);
    tabHost.getTabWidget().setBackgroundColor(Color.BLACK);
0

精彩评论

暂无评论...
验证码 换一张
取 消