2

有五個EditText小部件放置在第一個選項卡中,五個EditText小部件放置在第二個選項卡和五個EditText小部件放置在第三個選項卡中。現在我想通過單擊一個按鈕將所有選項卡的數據添加到數據庫中。 該按鈕不在標籤佈局內。它的線性佈局內... XML樹結構是這樣的:如何將所有選項卡的數據添加到數據庫中使用單個按鈕單擊Android

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#ffffff" > 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 
     <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="300dp" > 
     </FrameLayout> 
       <Button 
        android:id="@+id/submit" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="Submit" /> 
    </LinearLayout> 
</TabHost> 
+1

嘿你在哪裏添加EditTexts爲TabContent?它是另一個LinearLayout,你會膨脹並添加或者子活動或碎片? – TNR

+0

@ Nagaraj436:是的EditTexts是在另一個活動。當用戶點擊一個標籤時,其tabcontent被從另一個活動中調用。 代碼如下所示: '//對於歌曲詳細信息的選項卡 TabSpec DD = tabHost.newTabSpec(「songs Details」); DD.setIndicator(「songs details」,getResources()。getDrawable(R.drawable.dd)); Intent dd = new Intent(this,DropDetails.class); DD.setContent(dd);' –

+0

我希望這是不可能的,如果需要可以給另一個解決方案 – TNR

回答

1

是不會在tabcontent的每個活動結束把一個按鈕。你所做的是不採取3個單獨的活動不採取任何內部子活動。在主要活動中,將所有佈局(您將其設置爲活動的內容視圖)充氣,並將它們設置爲3個選項卡的內容。然後你將有3個觀看者被誇大。現在,創建EditTexts對象以查看透視圖並在點擊按鈕時使用它們。希望你瞭解我的想法。更重要的是,不建議使用「活動」作爲選項卡的內容,因爲它們消耗更多內存。我知道有很多教程遵循相同的原則,但隱藏了缺點。

0

我已經誇大了三項活動。所有這三個活動都包含EditTexts。代碼如下:

TabHost tabHost = getTabHost(); 

    // Tab for Photos 
    TabSpec photospec = tabHost.newTabSpec("Photos"); 
    photospec.setIndicator("General", getResources().getDrawable(R.drawable.icon_photos_tab)); 
    Intent photosIntent = new Intent(this, PhotosActivity.class); 
    photospec.setContent(photosIntent); 

    // Tab for Songs 
    TabSpec songspec = tabHost.newTabSpec("Songs"); 
    // setting Title and Icon for the Tab 
    songspec.setIndicator("Private", getResources().getDrawable(R.drawable.icon_songs_tab)); 
    Intent songsIntent = new Intent(this, SongsActivity.class); 
    songspec.setContent(songsIntent); 

    // Tab for Videos 
    TabSpec videospec = tabHost.newTabSpec("Videos"); 
    videospec.setIndicator("Other", getResources().getDrawable(R.drawable.icon_videos_tab)); 
    Intent videosIntent = new Intent(this, VideosActivity.class); 
    videospec.setContent(videosIntent); 


    // Adding all TabSpec to TabHost 
    tabHost.addTab(photospec); // Adding photos tab 
    tabHost.addTab(songspec); // Adding songs tab 
    tabHost.addTab(videospec); // Adding videos tab 

我已在所有3個標籤添加的EditText,我想通過點擊一個按鈕來添加所有3片(含有的EditText)到數據庫中的數據。並且按鈕是main.xml中 輸出爲波紋管:

output looks like this

相關問題