menu in android tutorial
Understand Menu option.
a. Create an application that will change color of the screen,based on selected options from the menu.
File Name : E7Activity.java
package bsr.exa;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.LinearLayout;
public class E7Activity extends Activity {
/** @author Bipin S Rupadiya , www.BipinRupadiya.blogspot.com
*
* 7) Understand Menu option.
* a. Create an application that will change color of the screen,
* based on selected options from the menu.
**/
LinearLayout ll;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ll= new LinearLayout(this);
ll.setOnCreateContextMenuListener(this);
setContentView(ll);
}
//For Option menu creation
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
CreateMenu(menu);
return true;
}
//For Option menu creation
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
return MenuChoice(item);
}
//For Context menu creation
@Override
public void onCreateContextMenu(ContextMenu menu, View view,ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, view, menuInfo);
CreateMenu(menu);
}
//For Context menu selection
@Override
public boolean onContextItemSelected(MenuItem item)
{
return MenuChoice(item);
}
private void CreateMenu(Menu menu)
{
MenuItem mnu1 = menu.add(0, 0, 0, "RED");
{
mnu1.setAlphabeticShortcut('r');
}
MenuItem mnu2 = menu.add(0, 1, 1, "GREEN");
{
mnu2.setAlphabeticShortcut('g');
//mnu2.setIcon(R.drawable.icon);
}
MenuItem mnu3 = menu.add(0, 2, 2, "BLUE");
{
mnu3.setAlphabeticShortcut('c');
}
}
private boolean MenuChoice(MenuItem item)
{
switch (item.getItemId())
{
case 0:
ll.setBackgroundColor(Color.rgb(255,0,0));
return true;
case 1:
ll.setBackgroundColor(Color.rgb(0,255,0));
return true;
case 2:
ll.setBackgroundColor(Color.rgb(0,0,255));
return true;
}
return false;
}
}
AndroidManifest.xml
<?xml version="1.0"
encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bsr.exa"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"
/>
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".E7Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
Labels:
Android,
Mobile Computing
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- CSS (3)
- Configure Tomcat7 (2)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- WTAD (34)
- c (11)
- install Tomcat (2)
- linux (8)
- shell script (33)
- unix (22)
Blog Archive
-
▼
2012
(79)
-
▼
September
(22)
- Chapter 7, Memory Management
- Chapter 6, Concurrency: Deadlock and Starvation
- Chapter 5, Concurrency: Mutual Exclusion and Sync...
- Chapter 4, Threads, SMP, and Micro kernels
- Chapter 3, Process Description and Control
- Chapter 2, Operating System Overview
- Chapter 1, Computer System Overview
- menu in android tutorial
- android animation example
- android chronometer example
- spinner in android example
- listview in android
- implicit intent in android example
- addTextChangedListener in Android example
- Be a Freelances and earn $$$$
- View SQLite Database
- Write a shell script to delete zero sized files fr...
- Android Intent Example
- Hello World in Android
- SQLite Android Tutorial
- Happy Teachers' Day
- Thank you GOD
-
▼
September
(22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.