Ich habe eine Anwendung über Schulden an Benutzer und Benutzer Schulden. Hauptaktivität ist TabActivity zum Wechseln zweier Aktivitäten mit benutzerdefinierten Listen.Wie man eine horizontal-umschaltbare Aktivitäten machen
Es sieht aus wie (Screenshot): http://i.stack.imgur.com/qts1f.png
Der Code ist:
public class MainActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
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
TextView tv = (TextView)findViewById(R.id.newDebtHeader);
tv.setBackgroundResource(R.drawable.grad);
tv.setTextColor(Color.BLACK);
tv.setFadingEdgeLength(3);
intent = new Intent().setClass(this, DebtsToMeList.class);
spec = tabHost.newTabSpec("debts_to_me").setIndicator(null, res.getDrawable(R.drawable.ic_tab_debts_to_me)).setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MyDebtsList.class);
spec = tabHost.newTabSpec("my_debts").setIndicator(null, res.getDrawable(R.drawable.ic_tab_my_debts)).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
main.xml ist:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dp">
<TextView
android:id="@+id/newDebtHeader"
android:layout_height="24dip"
android:layout_width="fill_parent"
android:gravity="center_vertical|center_horizontal"
android:textStyle="bold"
android:textSize="16dip"
android:text="хДолги">
</TextView>
<TabHost
android:id="@android: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"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
enter code here
Aber ich weiß nicht, wie TabActivity Ich möchte diese zwei Listen durch horizontalen Finger ziehen ändern. Könnten Sie mir bitte helfen, meinen Code zu ändern?
Vielen Dank! Es ist ein gutes Beispiel. Aber ich habe mit zwei anderen Problemen entdeckt ... 1. ist Berührung in Liste bereits von Liste übergeben, 2. Tabs werden nicht durch Methode tabHost.setCurrentTab (1); (Es sollte zu einem anderen Tab wechseln, aber nichts passiert. Mein sein muss eine Methode aufrufen, um erzwingen zu erzwingen ...) – pbelov
Ich habe mein Problem gelöst. Jetzt funktioniert es wie ich will. Um die Registerkarten zu wechseln, brauchen Sie 0 und 1 anstelle von 1 und 2. – pbelov