0% found this document useful (0 votes)
5 views3 pages

Android App with Menus and Alarms

The document contains the source code for an Android application with a main activity that includes a button to create an alarm, displaying a toast message upon clicking. It also defines a menu with three items (FYCS, SYCS, TYCS) that navigate to different activities when selected. Additionally, it includes XML layout files for the main activity and string resources.

Uploaded by

john.dow.1084
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Android App with Menus and Alarms

The document contains the source code for an Android application with a main activity that includes a button to create an alarm, displaying a toast message upon clicking. It also defines a menu with three items (FYCS, SYCS, TYCS) that navigate to different activities when selected. Additionally, it includes XML layout files for the main activity and string resources.

Uploaded by

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

mainActivity.

java

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


Button b3;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
b3 = (Button) findViewById([Link].b3);
[Link](new [Link]()

public void onClick(View v) {


[Link](getApplicationContext(), "alarm created",
Toast.LENGTH_LONG).show();
}

});
}
}
Activity_main.xml

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


<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="[Link]">

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/alarm"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b2"
android:layout_below="@id/b1"
android:src="@drawable/index"

/>

<Button
android:id="@+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/alarm"
android:onClick="onClick"
android:layout_below="@id/b2"
android:drawableLeft="@drawable/index"
tools:layout_editor_absoluteY="123dp"
tools:layout_editor_absoluteX="-17dp" />
</[Link]>

[Link]

<resources>
<string name="app_name">My Application</string>
<string name="alarm">alarm</string>
</resources>

Output

[Link] an application for working with Menus


XML Code:
[Create a menu - Android Resource Directory and create a main_menu.xml – Android
Resource File in it.]
[Link]
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="[Link]
xmlns:android="[Link]
<item
android:id="@+id/item1"
android:title="FYCS" />
<item
android:id="@+id/item2"
android:title="SYCS" />
<item
android:id="@+id/item3"
android:title="TYCS" />
</menu>

Source Code:

[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class AndroidMenusActivity extends AppCompatActivity {

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

public boolean onCreateOptionsMenu(Menu menu) {


//return [Link](menu);
MenuInflater menuInflater = getMenuInflater();
[Link]([Link], menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch ([Link]()) {
case [Link].item1:
startActivity(new Intent([Link], [Link]));
return true;
case [Link].item2:
startActivity(new Intent([Link], [Link]));
return true;
case [Link].item3:
startActivity(new Intent([Link], [Link]));
return true;
default:
return [Link](item);
}
}
}

You might also like