tags:

views:

46

answers:

1

How can I pass a string from an activity to a layout? I can pass arrays from an activity to a layout with the following activity code

    ListView remedyList = (ListView) findViewById(R.id.ListView_Symptom);
    String remedyArray[] = new String[30];
    ArrayAdapter<String> adapt = new ArrayAdapter<String>(this, R.layout.menu_item, remedyArray);
    remedyList.setAdapter(adapt);

Is there a simpler way to just pass a single string instead of any array of strings, from an activity to a layout?

+2  A: 

if you are thinking pass values to a layout, you want that values displayed in an element of the layout for example an Textview.

Suppossing you have a TextView inside your Layout.

<?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"
    android:background="#FFFFFF"
    >
<TextView  
    android:id="@+id/myTextView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"     
    />
</LinearLayout>

then you can set a string value to your TextView

String myText = "James";
TextView myTextView= (TextView) findViewById(R.id.myTextView);
myTextView.setText(myText);
Jorgesys