Code:package com.Demo.mc1;
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Output:
android.app.Activity;
android.os.Bundle;
android.util.Log;
android.view.Menu;
android.view.MenuItem;
Output:-
android.app.Activity;
android.os.Bundle;
android.util.Log;
android.view.Menu;
android.view.MenuItem;
android.widget.Toast;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
Output:-
Q4
Code:package com.mc.mc4;
import
import
import
import
import
import
import
import
import
import
import
android.app.Activity;
android.os.Bundle;
android.util.Log;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;
android.widget.EditText;
android.widget.TextView;
android.widget.Toast;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Output:-
b)CheckBox
c)SwitchButton
d)ToggleButton
Code:package com.wp.changewp;
import java.io.IOException;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
android.app.Activity;
android.app.WallpaperManager;
android.content.Context;
android.media.AudioManager;
android.os.Bundle;
android.os.Vibrator;
android.view.Menu;
android.widget.CheckBox;
android.widget.CompoundButton;
android.widget.CompoundButton.OnCheckedChangeListener;
android.widget.RadioGroup;
android.widget.Switch;
android.widget.Toast;
android.widget.ToggleButton;
else{
Toast.makeText(MainActivity.this, "Cb is Unchecked",
Toast.LENGTH_SHORT).show();
}
}
});
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
WallpaperManager
wm=WallpaperManager.getInstance(MainActivity.this);
switch(checkedId){
case R.id.radioButton1:
try {
wm.setResource(R.drawable.chrysanthemum);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.radioButton2:
try {
wm.setResource(R.drawable.jellyfish);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.radioButton3:
try {
wm.setResource(R.drawable.lighthouse);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
output:-
android.app.Activity;
android.content.Context;
android.media.AudioManager;
android.media.MediaPlayer;
android.os.Bundle;
android.view.Menu;
android.view.View;
android.widget.SeekBar;
android.widget.SeekBar.OnSeekBarChangeListener;
android.app.Activity;
android.app.NotificationManager;
android.content.Context;
android.hardware.Sensor;
android.hardware.SensorEvent;
android.hardware.SensorEventListener;
android.hardware.SensorManager;
android.os.Bundle;
android.speech.tts.TextToSpeech;
android.speech.tts.TextToSpeech.OnInitListener;
android.support.v4.app.NotificationCompat;
android.view.Menu;
android.widget.ImageView;
}
}
}
output:-
android.app.Activity;
android.graphics.Color;
android.os.Bundle;
android.telephony.SmsManager;
android.view.Menu;
android.view.View;
android.widget.Button;
android.widget.EditText;
android.widget.Toast;
android.annotation.SuppressLint;
android.app.Activity;
android.content.Context;
android.location.Address;
android.location.Geocoder;
android.location.Location;
android.location.LocationListener;
android.location.LocationManager;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.widget.TextView;
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
tvcoordinate.setText("lat:"+location.getLatitude()
+"Ing"+location.getLongitude());
lm.removeUpdates(this);
geo=new Geocoder(this,Locale.getDefault());
if(Geocoder.isPresent()){
try{
List<Address>
add=geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
StringBuilder sb=new StringBuilder();
Address addr=add.get(0);
for(int i=0;i<addr.getMaxAddressLineIndex();i++){
sb.append(addr.getAddressLine(i)+"\n");
}
sb.append(addr.getCountryName()+"\n");
sb.append(addr.getPhone()+"\n");
sb.append(addr.getPostalCode()+"\n");
tvaddress.setText(sb.toString());
}catch(IOException e){
e.printStackTrace();
}
}
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
// TODO Auto-generated method stub
}
}
output:-