1. Download our Official Android App: Forums for Android!

Apps how to create two textview in a xml file?

Discussion in 'Android Development' started by currycrab, Sep 14, 2011.

  1. currycrab

    currycrab Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    31
    Joined:
    Sep 11, 2011

    Sep 11, 2011
    31
    0
    15
    programming student
    somewhere
    i was asked to make 2 textview in an xml file.. where i am suppose to fill the data into the two textview. but i onli manage to make a textview. tried alot of methods but jux cnt make 2 textview in the same xml file

    here is the code in java

    Code (Text):
    1. private void initModuleMCTable() {
    2.         cursor = dbHelper.fetchAllModuleMCs();
    3.         startManagingCursor(cursor);
    4.        
    5.         if (cursor.getCount() == 0) {
    6.             Log.w(ModuleMCDatabaseHelper.class.getName(),"intit modulemc table");
    7.             dbHelper.createModuleMC("EG1011", "Mr Tan", "S441");
    8.             dbHelper.createModuleMC("EG1012", "Mr Tan", "S441");
    9.             dbHelper.createModuleMC("EG1013", "Mr Wong", "S442");                        
    10.         }
    11.     }
    12.    
    13.     private void fillData() {
    14.         cursor = dbHelper.fetchAllModuleMCs();
    15.         startManagingCursor(cursor);
    16.        
    17.         // Now create an array adapter and set it to display using our row
    18.         SimpleCursorAdapter modulesAdapter = new SimpleCursorAdapter(this,R.layout.list_item, cursor,
    19.                            new String[] { ModuleMCDbAdapter.KEY_MODULE_CODE ,ModuleMCDbAdapter.KEY_MC},
    20.                            new int[] { R.id.label});
    21.         setListAdapter(modulesAdapter);        
    22.     }

    the below is the code in xml i only manage to get 1 done but doesnt know how to make the 2nd textview

    Code (Text):
    1. <TextView xmlns:android="http://schemas.android.com/apk/res/android"
    2.     android:id="@+id/label"
    3.     android:layout_width="fill_parent"
    4.     android:layout_height="fill_parent"
    5.     android:padding="10dp"
    6.     android:textSize="16sp"
    7.     android:gravity="center_vertical|center_horizontal"
    8.  
    9.      >
    10. </TextView>
    11.  
    12.  
     

    Advertisement

  2. qasimValent

    qasimValent Member
    Rank:
    None
    Points:
    16
    Posts:
    39
    Joined:
    Jun 29, 2010

    Jun 29, 2010
    39
    6
    16
    RG
    Okay so the purpose of this is what? Like what are you trying to aim for?


    btw for two text views you could just declare another textview in your xml file, so copy and paste the original below all under a linear layout, but just change the id.
     
  3. qasimValent

    qasimValent Member
    Rank:
    None
    Points:
    16
    Posts:
    39
    Joined:
    Jun 29, 2010

    Jun 29, 2010
    39
    6
    16
    RG
    Do you mean something like this?


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

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_height="fill_parent" android:layout_width="fill_parent">


    <​
    TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="hi"></TextView>

    <TextView android:id="@+id/textView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="hello"></TextView>


    </LinearLayout>

     
  4. matejm1994

    matejm1994 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jan 8, 2011

    Jan 8, 2011
    5
    0
    5
    Yes, you are right. BTW: There is a code below with 2 TextView. It is very simple...

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent"
    6.     >
    7.    
    8.     <TextView   android:id="@+id/textView1"
    9.                 android:text="TextView"
    10.                 android:layout_height="wrap_content"
    11.                 android:layout_width="wrap_content">
    12.             </TextView>
    13.     <TextView   android:text="TextView"
    14.                 android:id="@+id/textView2"
    15.                 android:layout_width="wrap_content"
    16.                 android:layout_height="wrap_content">
    17.             </TextView>
    18. </LinearLayout>
     
  5. currycrab

    currycrab Member
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    31
    Joined:
    Sep 11, 2011

    Sep 11, 2011
    31
    0
    15
    programming student
    somewhere
    ok erm. wad i meant is like for example.

    in a linear layout. i want a textview on the left and i want the 2nd textview to be on the same level. but on the right for the first textview.
     
  6. matejm1994

    matejm1994 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    5
    Joined:
    Jan 8, 2011

    Jan 8, 2011
    5
    0
    5
    You mean like this? You need another horizontal layout.

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     android:orientation="vertical"
    4.     android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent"
    6.     >
    7.     <LinearLayout   android:layout_width="fill_parent"
    8.                     android:id="@+id/linearLayout1"
    9.                     android:layout_height="wrap_content"
    10.                 >
    11.         <TextView   android:id="@+id/textView2"
    12.                     android:layout_height="wrap_content"
    13.                     android:text="TextView"
    14.                     android:layout_width="wrap_content">
    15.                 </TextView>
    16.         <TextView   android:id="@+id/textView1"
    17.                     android:layout_height="wrap_content"
    18.                     android:text="TextView"
    19.                     android:layout_width="wrap_content">
    20.             </TextView>
    21.     </LinearLayout>
    22. </LinearLayout>
    23.  
     

Share This Page

Loading...