Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old September 14th, 2011, 04:41 AM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Sep 2011
Location: somewhere
Posts: 31
 
Device(s):
Carrier: Not Provided

Thanks: 4
Thanked 0 Times in 0 Posts
Default how to create two textview in a xml file?

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:
private void initModuleMCTable() {
        cursor = dbHelper.fetchAllModuleMCs();
        startManagingCursor(cursor);
        
        if (cursor.getCount() == 0) {
            Log.w(ModuleMCDatabaseHelper.class.getName(),"intit modulemc table");
            dbHelper.createModuleMC("EG1011", "Mr Tan", "S441");
            dbHelper.createModuleMC("EG1012", "Mr Tan", "S441");
            dbHelper.createModuleMC("EG1013", "Mr Wong", "S442");                        
        }
    }
    
    private void fillData() {
        cursor = dbHelper.fetchAllModuleMCs();
        startManagingCursor(cursor);
        
        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter modulesAdapter = new SimpleCursorAdapter(this,R.layout.list_item, cursor, 
                           new String[] { ModuleMCDbAdapter.KEY_MODULE_CODE ,ModuleMCDbAdapter.KEY_MC}, 
                           new int[] { R.id.label});
        setListAdapter(modulesAdapter);        
    }

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

Code:
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/label"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp" 
    android:textSize="16sp"
    android:gravity="center_vertical|center_horizontal"

     > 
</TextView>

currycrab is offline  
Reply With Quote
sponsored links
Old September 14th, 2011, 10:11 AM   #2 (permalink)
Junior Member
 
Join Date: Jun 2010
Location: RG
Posts: 39
 
Device(s): DELL STREAK
Carrier: Not Provided

Thanks: 0
Thanked 6 Times in 6 Posts
Send a message via MSN to qasimValent
Default

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.
qasimValent is offline  
Reply With Quote
Old September 14th, 2011, 10:22 AM   #3 (permalink)
Junior Member
 
Join Date: Jun 2010
Location: RG
Posts: 39
 
Device(s): DELL STREAK
Carrier: Not Provided

Thanks: 0
Thanked 6 Times in 6 Posts
Send a message via MSN to qasimValent
Default

Do you mean something like this?


<?
xmlversion="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">


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

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


</LinearLayout>

qasimValent is offline  
Reply With Quote
Old September 14th, 2011, 02:11 PM   #4 (permalink)
New Member
 
Join Date: Jan 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes, you are right. BTW: There is a code below with 2 TextView. It is very simple...

Code:
<?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"
    >
    
    <TextView 	android:id="@+id/textView1" 
    			android:text="TextView" 
    			android:layout_height="wrap_content" 
    			android:layout_width="wrap_content">
    		</TextView>
    <TextView 	android:text="TextView" 
    			android:id="@+id/textView2" 
    			android:layout_width="wrap_content" 
    			android:layout_height="wrap_content">
    		</TextView>
</LinearLayout>
matejm1994 is offline  
Reply With Quote
Old September 14th, 2011, 08:30 PM   #5 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Sep 2011
Location: somewhere
Posts: 31
 
Device(s):
Carrier: Not Provided

Thanks: 4
Thanked 0 Times in 0 Posts
Default

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.
currycrab is offline  
Reply With Quote
Old September 15th, 2011, 03:12 AM   #6 (permalink)
New Member
 
Join Date: Jan 2011
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Default

You mean like this? You need another horizontal layout.

Code:
<?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"
    >
    <LinearLayout 	android:layout_width="fill_parent" 
    				android:id="@+id/linearLayout1" 
    				android:layout_height="wrap_content"
    			>
        <TextView 	android:id="@+id/textView2" 
        			android:layout_height="wrap_content" 
        			android:text="TextView" 
        			android:layout_width="wrap_content">
        		</TextView>
        <TextView 	android:id="@+id/textView1" 
        			android:layout_height="wrap_content" 
        			android:text="TextView" 
        			android:layout_width="wrap_content">
        	</TextView>
    </LinearLayout>
</LinearLayout>
matejm1994 is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:21 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.