如何在布局中动态显示名称?

How to display Name in your Layout dynamically?

我正在开发一个 Android 应用程序,它需要一个好友列表。我正在与服务器通信,服务器 returns 我 "Name",如何在我的布局中显示此名称。

我的xml代码:

 <LinearLayout 
    android:gravity="top" 
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="horizontal" > 
 <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="My Friend List" />
 </LinearLayout>

 <View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/darker_gray"/>

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:gravity="top"
    android:orientation="horizontal" >

 <ImageButton
     android:id="@+id/imageButton1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/add_more_friends" />

</LinearLayout>

</LinearLayout>

你可以在你的布局中的某个地方有一个 TextView 然后你发现 TextView 使用 findViewById 然后你在那个 TextView 上使用 setText 通过你的名字.