开发者

Multiple layout in one Tabactivity

开发者 https://www.devze.com 2023-02-09 17:17 出处:网络
How could I few layout and require to create in one Tabactivity. I have try the code below but no luck got error.

How could I few layout and require to create in one Tabactivity.

I have try the code below but no luck got error.

    tabHost.addTab(tabHost.newTabSpec("Sales Order").setIndicator("Sales Order").setContent(R.layout.frm_txn_so_item_list));

OK let me explain clearly.

I have a code below, as you can see I have 4 tab layout page. Each of it has it own activity class. I have a button which is belong to cls_so_item_list.class, whenever I am try to call it in my cls_so it always return me null value.

So I have come out an idea, to remove all the tab page(item,product,summary,Report) activity classes then create it one standalone class which is cls_so.

My question is how do I put the layout page inside the tabHost.addTab? Thanks

public class cls_so extends TabActivity implements OnClickListener {
    protected TabHost tabHost;

    int intSalesOrderId;
    src_txn_so.cls_so_obj objSales开发者_JAVA百科Order;
    static final String LIST_ID = "list_id";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tabHost = getTabHost();

        newTabIntent("Item", null, cls_so_item_list.class);
        newTabIntent("Product",
                getResources().getDrawable(R.drawable.so_product),
                cls_so_prd_list.class);
        newTabIntent("Summary",
                getResources().getDrawable(R.drawable.so_summary),
                cls_so_summary.class);
        newTabIntent("Report",
                getResources().getDrawable(R.drawable.so_report),
                cls_so_summary.class);


        Button btnSOLineDiscount = (Button) findViewById(R.id.txn_so_btn_line_discount);
        btnSOLineDiscount.setOnClickListener(this);

        tabHost.setCurrentTab(0);
    }

    protected void newTabIntent(String label, Drawable icon, Class<?> pageClass) {
        TabSpec tabSpec = tabHost.newTabSpec(label);
        tabSpec.setIndicator(label, icon);

        Intent SOIntent = new Intent().setClass(this,pageClass);
        SOIntent.putExtra(LIST_ID, -1);

        tabSpec.setContent(new Intent(this, pageClass));
        tabHost.addTab(tabSpec);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }


}


It doesn't work like that. In your main layout, add in the FrameLayout with the id of tabcontent an element <include> that points on that layout.

In your code you'll have to change it to.

tabHost.addTab(tabHost.newTabSpec("Sales Order").setIndicator("Sales Order").setContent(R.id.my_included_layout));

if you're <include> has the id "@+id/my_included_layout"

0

精彩评论

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