2011-02-24 10 views
9

दाएं मेरे पास एक मुख्य लेआउट परिभाषित किया गया है, जिसमें फ्रेम है, उस फ्रेम में एक तालिका है और उसके बाद बटन के लोड के साथ एक क्षैतिज स्क्रॉल दृश्य है। जब बटन क्लिक किया जाता है तो फ्रेम की सामग्री को एक नई तालिका में बदलना चाहिए, जैसे कि जब आप टैब लेआउट ट्यूटोरियल में एक अलग टैब चुनते हैं (टैब लेआउट का उपयोग नहीं करते क्योंकि मेरे पास बहुत सारे बटन हैं जो स्क्रीन पर फिट नहीं होते हैं स्क्रॉल)बटन पर framelayout की सामग्री को बदलना

<?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="5dp"> 
     <FrameLayout 
      android:id="@+id/tabcontent" 
      android:layout_width="fill_parent"    
      android:layout_height="wrap_content" 
      android:layout_weight="1.2"    
      android:padding="5dp" android:background="@color/white"> 
      <TableLayout android:id="@+id/Jobs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*"> 
       <TableRow android:id="@+id/JobRow" android:layout_width="wrap_content" android:layout_height="wrap_content"> 
        <TextView android:id="@+id/JobID" android:layout_column="1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView> 
        <TextView android:id="@+id/JobStatus" android:layout_column="2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView> 
        <TextView android:id="@+id/Customer" android:layout_column="3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView> 
        <TextView android:id="@+id/Department" android:layout_column="4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView> 
        <TextView android:id="@+id/DocType" android:layout_column="5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/black"></TextView> 
       </TableRow> 
      </TableLayout> 
     </FrameLayout> 
     <HorizontalScrollView 
      android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="bottom" android:scrollbars="none"> 
      <LinearLayout 
       android:orientation="horizontal" android:layout_height="wrap_content" 
       android:layout_width="fill_parent"> 
       <ImageButton android:id="@+id/batching" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/batching"></ImageButton> 
       <ImageButton android:id="@+id/merging" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/merging"></ImageButton> 
       <ImageButton android:id="@+id/processing" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
       <ImageButton android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/processing"></ImageButton> 
      </LinearLayout> 
     </HorizontalScrollView> 
</LinearLayout> 
टैब की सामग्री को बदलने के लिए टैब

अब तो जैसे काफी आसान लग रहा था:

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 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, ArtistsActivity.class); 

    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost.newTabSpec("artists").setIndicator("Artists", 
         res.getDrawable(R.drawable.ic_tab_artists)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

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

    intent = new Intent().setClass(this, SongsActivity.class); 
    spec = tabHost.newTabSpec("songs").setIndicator("Songs", 
         res.getDrawable(R.drawable.ic_tab_songs)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(2); 
} 

मैं फ्रेम सामग्री और बटन के साथ कुछ इसी तरह कैसे कर सकता है? मैं

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);  

    Resources res = getResources(); // Resource object to get Drawables 
    final Intent batchingIntent, mergingIntent, processingIntent; 

    // Create an Intent to launch an Activity for the tab (to be reused)   


    final Button batchButton = (Button) findViewById(R.id.batching); 
    batchingIntent = new Intent().setClass(this, BatchingActivity.class); 
    batchButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      // Perform action on clicks 
      FrameLayout frame = (FrameLayout) findViewById(R.id.tabcontent); 
      frame.setContent(batchingIntent) // doesn't exist obviously 
     } 
    }); 

उत्तर

24

के साथ कुछ सोच रहा था आप फ़्रेमलेआउट के अंदर किसी गतिविधि को घोंसला नहीं दे सकते।

LayoutInflater.from(context).inflate(R.other_tab, frame, true);

: इसके बजाय विचारों को जोड़ने आप भी FrameLayout में एक लेआउट बढ़ सकता है की


FrameLayout frame = (FrameLayout) findViewById(R.id.tabcontent); 
frame.removeAllViews(); 
frame.addView(aNewViewOne); 
frame.addView(aNewViewTwo); 
... 

: आप क्या कर सकते नए लोगों के साथ अपने विचारों को स्वैप है

संबंधित मुद्दे