4

Hey all, first post and a noob in Android programming, but willing to learn! Basically I've taken the Google sample of a tab layout from here

I found that method to be very easy to create tabs with text within each tab, but I'm trying to make it so that when a tab is selected, I want the text listed below to be separated by a dividing line. So that a line is dividing between each paragraph, however I'm having trouble doing this. This is what I have so far: main.xml:

<?xml version="1.0" encoding="utf-8"?>

        <TableRow>
            <TextView
            android:id="@+id/textview1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="this is the FIRST line of the 1st tab" />
            <TextView
            android:id="@+id/textview1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="this is the SECOND line of the 1st tab" />
            </TableRow>
            <View
    android:layout_height="2dip"
    android:background="#FF909090" />

    <TableRow>
        <TextView 
            android:id="@+id/textview2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="this is First line of the 2nd tab" />
            </TableRow>
            <View
    android:layout_height="2dip"
    android:background="#FF909090" />
            <View
    android:layout_height="2dip"
    android:background="#FF909090" /> 
         <TextView 
            android:id="@+id/textview3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="this is the First line of the 3rd tab" />
         <TextView 
            android:id="@+id/textview4"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="This is the First line of the 4th tab." />

            </TableLayout>
     </FrameLayout>

Here is the info in the java file:

  public class HelloTabWidget extends TabActivity {

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

        TabHost mTabHost = getTabHost();

 mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent(R.id.textview1));       
 mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
 mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));
 mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("TAB 4").setContent(R.id.textview4));
        mTabHost.setCurrentTab(0);
    }
}

In main.xml I can get "this is the FIRST line of the 1st tab" on the first line, but "this is the SECOND line of the 1st tab" is showing up in the first line, and in all other tabs. Thanks in advance for any help, hopefully with my gained knowledge I can help others in the future.

Shruti
  • 1
  • 13
  • 55
  • 95
Clozecall
  • 101
  • 1
  • 2
  • 9

1 Answers1

21

If you simply want a separator (line dividing the area into two sections), you can use the following code in your layout XML file;

<View   android:id="@+id/firstDivider"
        android:layout_height="2dp"
        android:layout_width="fill_parent"
        android:background="#000080" />

The above code will produce a 2dp thick, navy blue divider. Increasing the layout_height will increase the thickness of divider.

Revert back for any query.

Mudassir
  • 13,031
  • 8
  • 59
  • 87
  • Thanks for the very quick response, however the code you gave is almost the same thing that I have. What I'm trying to do is put text under each tab, the text under each tab I want in seperate paragraphs, and inbetween each paragraph I want a line going through. Thus far I was able to put the text in seperate paragraphs by doing this: – Clozecall Jan 03 '11 at 15:10
  • Using \n creates a new paragraph within each tab, but I want more than one paragraph, and a line divinding through each one. -Thanks. – Clozecall Jan 03 '11 at 15:12
  • @mudassir : can i create a divider through java code ? if yes then how ?? please reply its urgent – Shruti May 28 '13 at 09:10
  • 1
    @Shruti: Yes, you can. Try this, http://stackoverflow.com/questions/15622711/linearlayout-programmatically-how-to-set-up-a-divider#15622754 – Mudassir May 28 '13 at 09:28
  • 1
    @Mudassir : thanks for the spontaneous response .. it helped me – Shruti May 28 '13 at 09:33