2

There is five EditText widget placed in first tab, five EditText widget placed in second tab and five EditText widget placed in third tab. Now i want to add the data of all the tabs into database by clicking on a single button. The button is not inside the tab layout. its inside the linear layout... The xml tree structure is like this:

<?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>
Ankit Dhadse
  • 1,566
  • 1
  • 15
  • 19
  • 1
    hey where are you adding EditTexts as TabContent? is it another LinearLayout you will inflate and add or else subactivities or Fragments? – TNR Dec 02 '12 at 07:35
  • @Nagaraj436: Yes the EditTexts are in a yet another activity. when user click on a tab its tabcontent is called from another activity. the code goes like this: `// Tab for Song Details 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);` – Ankit Dhadse Dec 03 '12 at 14:28
  • I hope that is not possible, if required can give another solution – TNR Dec 03 '12 at 14:30
  • Ya... please sir... what can be an alternate solution to this.. – Ankit Dhadse Dec 03 '12 at 14:31
  • I dont want to keep a Button at the end of each activity of the tabcontent.. hope you understand. – Ankit Dhadse Dec 03 '12 at 14:33

2 Answers2

1

Yes don't put a button at the end of each activity of the tabcontent. What you do is instead of taking 3 separate Activities don't take any internal sub activities. In your main Activity, Inflate all the layouts(which you are setting as content view for activities) and set them as content for the 3 Tabs. Then you will have 3 Views which are inflated. Now Create the EditTexts object with respect to view perspective and use them when clicked on the button. Hope you understand my Idea. And more importantly it is not suggested to use Activities as contents of Tabs as they consume more memory. I know there are many tutorials which follow the same but hide the drawback.

TNR
  • 5,839
  • 3
  • 33
  • 62
0

I have inflated three activity. all all the three activity contains EditTexts. The code is as follows:

    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

I have added EditText in all 3 tabs and i want to add the data of all 3 tab(Containing EditText) to database by clicking on a single button. and the button is in main.xml The output is as bellow:

output looks like this

Ankit Dhadse
  • 1,566
  • 1
  • 15
  • 19