0
What should i learn for selecting element from XML file in java android devlopement.
3 ответов
+ 1
ID of the element in the xml file.
In the java file, access this element by id.
+ 1
Xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/tvOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="50dp"
android:text="TextView">
</TextView>
</LinearLayout>
+ 1
Java class file:
public class MainActivity extends Activity {
TextView tvOut;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvOut = (TextView) findViewById(R.id.tvOut);
tvOut. setText("New some text");
}
}