• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps how to create two textview in a xml file?

currycrab

Newbie
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>
 
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.
 
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>

 
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>
 
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.
 
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>
 
Back
Top Bottom