2010-12-15 104 views
1

Comment afficher TabActivity dans AlertDialog? Je sais que c'est un peu difficile, car nous devrions exécuter TabActivity comme activité normale,Android TabActivity dans AlertDialog

par exemple.

Intent intent = new Intent(MyClass.this, Settings.class); 
startActivity(intent); 

où Paramètres - TabActvivity.

La seule façon dont je le sais pour définir la vue pour AlertDialog, mais cela ne fonctionnera pas.

View view = (View) ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)) 
    .inflate(R.layout.settings, null); 
new AlertDialog.Builder(this).setTitle("AlertDialog").setView(view).show(); 

Est-il possible d'afficher TabActivity dans AlertDialog?

Merci,

Répondre

4

Vous amalgamant en quelque sorte le concept de vues et activités, mais sans doute la meilleure façon de faire ce que vous voulez est de définir le thème de votre TabActivity-Theme.Dialog et commencer, au lieu de en utilisant un AlertDialog et en essayant d'envelopper un Activity dans un popup dans un autre Activity. Pour votre propre santé mentale, ne descendez pas cette route dans le territoire de type Inception.

3

Je ne vais pas vous recommande vraiment cette approche mais puisque vous avez demandé le comportement Heres un exemple de code:

Heres un onglet mise en page, qui a une EditText dans tab1 et un Button dans tab2

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent">  
<LinearLayout 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<TabWidget android:id="@android:id/tabs" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
/> 

<FrameLayout android:id="@android:id/tabcontent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout android:id="@+id/tab1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:layout_centerHorizontal="true" 
    > 
    <EditText 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:hint="TextBox" 
    /> 

    </LinearLayout> 
<Button android:id="@+id/tab2" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:text="A semi-random button" 
/> 
</FrameLayout></LinearLayout></TabHost> 
code

pour gonfler cette mise en page à un AlertDialog

AlertDialog.Builder builder=new AlertDialog.Builder(this); 
    LayoutInflater inflator=getLayoutInflater(); 
    View view=inflator.inflate(R.layout.main, null); 

    TabHost tabHost=(TabHost)view.findViewById(R.id.tabhost); 
    tabHost.setup(); 
    TabHost.TabSpec spec=tabHost.newTabSpec("tag1"); 
    spec.setContent(R.id.tab1); 
    spec.setIndicator("Clock"); 
    tabs.addTab(spec); 

    spec=tabHost.newTabSpec("tag2"); 
    spec.setContent(R.id.tab2); 
    spec.setIndicator("Button"); 
    tabs.addTab(spec); 

    builder.setView(view); 
    builder.setPositiveButton("OK", null); 
    builder.create().show(); 

Comme je l'ai dit N'EST PAS CONSEILLÉ APPROCHE créer un thème plutôt que comme suggéré par Yoni Samlan ci-dessus.

+0

Si j'ai une vue inflator alors comment puis-je passer ID à setContent? – chhameed