当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How do I create a Dialog with Tabs

问题描述:

Is it possible to create a Dialog that has Tabs?

If possible, by selecting one of the Tabs I have to call an Activity, is it possible to pass values ​​through a Bundle?

网友答案:

you can use tabHost class of android for that purpose. http://developer.android.com/reference/android/widget/TabHost.html

in the onItemClick in the list, retrieve the customer name and put it in the intent and call the class that expends tabActivity like this,

Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
Bundle b = new Bundle();
b.putString("name", name);
intent.putExtras(b);
startActivity(intent);
finish();

at the tab activity remove the data from bundle

Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Resusable TabSpec for each tab
    Intent intent; // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, firsttabActivity.class);
    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("first").setIndicator("first", res.getDrawable(R.drawable.ic_tab_shuffle)).setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, secondtabActivity.class);
    spec = tabHost.newTabSpec("second").setIndicator("second", res.getDrawable(R.drawable.ic_tab_shuffle)).setContent(intent);
    tabHost.addTab(spec);

now u can pass the customer name along with the intents in the tab and make the activities extract it and use your own logic to use customer name to retrieve customers details. i dont know if there is any more effecient way to do it. this just happened to come to my mind first. i hope it helps.

分享给朋友:
您可能感兴趣的文章:
随机阅读: