0% found this document useful (0 votes)
2 views2 pages

Android

The document outlines a standard structure for an Android activity with functionality for a counter, changing font size, changing text color, and displaying a toast message. It includes code snippets for each functionality, demonstrating how to implement button click listeners to modify a TextView. The counter increments or decrements a value, the font size increases with a limit, text color cycles through predefined colors, and a welcome message is shown using a Toast from an EditText input.

Uploaded by

Lokesh Rajasekar
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)
2 views2 pages

Android

The document outlines a standard structure for an Android activity with functionality for a counter, changing font size, changing text color, and displaying a toast message. It includes code snippets for each functionality, demonstrating how to implement button click listeners to modify a TextView. The counter increments or decrements a value, the font size increases with a limit, text color cycles through predefined colors, and a welcome message is shown using a Toast from an EditText input.

Uploaded by

Lokesh Rajasekar
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

Standard structure

public class MainActivity extends Activity {

int count = 0; // declare variables here (outside onCreate)

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

// PUT YOUR FUNCTIONALITY CODE HERE


}
}

FUNCTIONALITY CODE OF ALL PROGRAMS

3. Counter (+1 / -1)


TextView tv = findViewById([Link]);

Button b1 = findViewById([Link]);

Button b2 = findViewById([Link].button2);

[Link](v -> {

count++;

[Link]("Count = " + count);

});

[Link](v -> {

count--;

[Link]("Count = " + count);

});

4. Change Font Size


TextView t = findViewById([Link].textView1);

Button b1 = findViewById([Link].button1);

[Link](v -> {

[Link](font);

font += 5;

if (font == 50)
font = 30;

});

4. Change Text Color


TextView t = findViewById([Link].textView1);

Button b2 = findViewById([Link].button2);

[Link](v -> {

ch++;

if (ch == 7)

ch = 1;

switch (ch) {

case 1: [Link]([Link]); break;

case 2: [Link]([Link]); break;

case 3: [Link]([Link]); break;

case 4: [Link]([Link]); break;

case 5: [Link]([Link]); break;

case 6: [Link]([Link]); break;

});

5. EditText + Toast
EditText t = findViewById([Link].et1);

[Link](this,

"Welcome " + [Link]().toString(),

Toast.LENGTH_LONG).show();

You might also like