所以这可能是个愚蠢的问题,但我对Android并不熟悉,也无法真正理解这是什么。我的意思是,没有那一条线,一切都很顺利。那么,它是否像一个保持变量呢?如果有人能给我举个例子,说明为什么需要这样做,或者给出一个很好的解释。
android:id="@+id/edit_message"我的全部代码都在这里:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.myfirst.MainActivity" >
<EditText android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
/>
</LinearLayout>发布于 2014-07-30 07:21:21
id是帮助您从代码(活动和类)获取视图的标识符。
android:id="@+id/edit_message"
在一个活动中,您可以使用以下代码获取这个文本视图(如果显示的话):
TextView editMessage = (TextView) findByView(R.id.edit_message);当您掌握了TextView,您可以更改它的值,从您的代码。
editMessage.setText("new text"); 那么,当您可以在代码中创建所有视图时,我们为什么要使用XML呢?它的编程非常简单,而且易于阅读。您还可以创建新的XML字段,它可以动态地适应系统的语言,例如。
https://stackoverflow.com/questions/25030874
复制相似问题