2010-12-15 22 views
1

Wie TabActivity in AlertDialog anzeigen? Ich weiß, dass es ein bisschen schwierig ist, da wir TabActivity als normale Aktivität,Android TabActivity in AlertDialog

z.

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

wo Einstellungen - TabActvivity.

Der einzige Weg, ich weiß es, um für AlertDialog anzuzeigen, aber es wird nicht funktionieren.

Gibt es eine Möglichkeit, TabActivity in AlertDialog anzuzeigen?

Danke,

Antwort

4

Sie Art das Konzept der Ansichten und Aktivitäten hier, conflating aber wahrscheinlich der einfachste Weg, was Sie tun wollen, ist Ihr TabActivity ‚s Thema Theme.Dialog und beginnen, es zu setzen, statt Verwenden Sie eine AlertDialog und versuchen, ein Activity in einem Popup in einem anderen Activity zu wickeln. Um deiner eigenen Gesundheit willen, geh nicht diese Straße in das Land der Einweihung.

3

Ich werde nicht wirklich diesen Ansatz empfehlen, aber da Sie das Verhalten angefordert heren ein Beispielcode:

Heres ein Tab Layout, die ein EditText in tab1 und Button in tab2

hat
<?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 dieses Layout ein AlertDialog

aufzublasen
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(); 

Wie ich sagte, dies sei ANSATZ ABGERATEN ein Thema erstellen, anstatt wie von Yoni Samlan oben.

+0

Wenn ich eine Inflatoransicht habe, wie kann ich ID an setContent übergeben? – chhameed