Android的 - 从活动传递字符串布局? [英] android - pass string from activity to layout?

查看:199
本文介绍了Android的 - 从活动传递字符串布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以通过从活动到布局的字符串? 我可以从一个活动传递阵列布局与下面的活动$​​ C $ C

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?

推荐答案

如果你正在考虑传值的布局,你希望那显示在例如布局的元素值的TextView的。

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你有一个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>

,那么你可以将字符串值设置为您的TextView

then you can set a string value to your TextView

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

这篇关于Android的 - 从活动传递字符串布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆