0% found this document useful (0 votes)
10 views1 page

Android XML and Java Code Example

The document contains XML and Java code for an Android application. The XML defines a layout with a TextView and a Button, while the Java code implements the MainActivity class that sets up the UI and handles button clicks to log messages and update the TextView. The button click triggers a background thread that continuously logs a message and updates the UI with the text 'XYZ'.

Uploaded by

rajpatilp112
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Android XML and Java Code Example

The document contains XML and Java code for an Android application. The XML defines a layout with a TextView and a Button, while the Java code implements the MainActivity class that sets up the UI and handles button clicks to log messages and update the TextView. The button click triggers a background thread that continuously logs a message and updates the UI with the text 'XYZ'.

Uploaded by

rajpatilp112
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

XML CODE:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NAME"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
JAVA CODE:
package [Link].p_26;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
TextView textView;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
textView = (TextView) findViewById([Link]);
button = findViewById([Link]);
ExecutorService service = [Link]();

[Link](v ->{
[Link](new Runnable() {
@Override
public void run() {
while (true){
Log.e("@@@" , "run:");
}
}
});

runOnUiThread(new Runnable() {
@Override
public void run() {
[Link]("XYZ");
}
});
});
}
}

You might also like