मैं एक टैबड लेआउट के साथ एक एंड्रॉइड एप्लिकेशन विकसित कर रहा हूं। मुझे यह पता चला है कि यह Google's tutorial suggested जैसी नई गतिविधि नहीं पैदा करता है, हालांकि मैंने प्रत्येक टैब पर क्लिक करते समय अपनी सामग्री को दिखाने के लिए इसे केवल एक प्रयास में किया है। वर्तमान में यह केवल टैब दिखाता है कि कौन सा टैब सक्रिय है।एंड्रॉइड टैब्ड लेआउट सेट सामग्री
के बाद अपने नवीनतम यात्रा में मेरे कोड है:
Main.java
public class Main extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
// add orders tab
spec = tabHost.newTabSpec("orders").setIndicator("Orders",
res.getDrawable(R.drawable.flash_36))
.setContent(R.id.ordersLayout);
tabHost.addTab(spec);
// add positions tab
spec = tabHost.newTabSpec("positions").setIndicator("Positions",
res.getDrawable(R.drawable.small_tiles_36))
.setContent(R.id.positionsLayout);
tabHost.addTab(spec);
// add strategies tab
spec = tabHost.newTabSpec("strategies").setIndicator("Strategies",
res.getDrawable(R.drawable.cards_36))
.setContent(R.id.strategiesLayout);
tabHost.addTab(spec);
// add account tab
spec = tabHost.newTabSpec("account").setIndicator("Account",
res.getDrawable(R.drawable.seal_36))
.setContent(R.id.accountLayout);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
}
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/mainLayout"
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">
</TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:padding="5dp">
<include layout="@layout/orders"/>
<include layout="@layout/positions"/>
<include layout="@layout/strategies"/>
<include layout="@layout/account"/>
</FrameLayout>
</LinearLayout>
</TabHost>
Account.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/accountLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="Account Information"
android:id="@+id/accountLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
Orders.xml
मैं केवल इन दो शामिल कर रहा हूँ, वे LinearLayout के एंड्रॉयड के लिए उपयुक्त आईडी के साथ सब ठीक उसी प्रकार हैं: आईडी पैरामीटर।
आदेश टैब
पदों टैब
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/ordersLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="Working Orders"
android:id="@+id/ordersLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
और यहाँ मैं क्या मिलेगा जब टैब के बीच स्विच करने का एक स्क्रीनशॉट
यह एम्यूलेटर और सैमसंग गैलेक्सी दोनों के लिए सच है, और मैं किसी भी विचार से, जिस तरह से बहुत अधिक प्रतिक्रिया देता हूं?
+1 और एक बहुत अच्छी व्याख्या। – Subby