Professional Documents
Culture Documents
Ma Front Page
Ma Front Page
Procedure:
Step 1: Open File menu→New→New project.
Step 2: Under configuration your new project, fill in the fields. Fill the application name where
the first letter should start with caps then other fields keep remain same as it is. Give the name
for your application click next.
Step 3: By default make phone and tablet selected and set the minimum SDK as API 16 and 4.1
(Jelly Bean).
Step 4: Select blank activity from the list of activity displayed. Click Next.
Step 5: Click next with the default activity name i.e. Main Activity.
Step 6: Open Content_main.xml file and look for the attribute android:text=”Hello World”.
OUTPUT :
Procedure:
Step1: Create a new project and give appropriate application name.
MainActivity.java
import android.widget.Toast;
android:configChanges="orientation|screenSize"
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE)
{
Toast toast =Toast.makeText(this,"this is landscape view",Toast.LENGTH_LONG);
toast.show();
}
else if (newConfig.orientation==Configuration.ORIENTATION_PORTRAIT)
{
Toast toast = Toast.makeText(this, "this is portrait view", Toast.LENGTH_LONG);
toast.show();
}
Step6: Use ctrl+F11 key to see the orientation changes of the screen.
OUTPUT :
Procedure:
Step 1: Open the new project and give appropriate application name.
Step 5: Open splashh.xml file in design tab, drag and drop one image view control.
tools:showIn=”@layout/activity_main”/>
Step 7: Go to project explorer window and create splash.java file under java folder.
Step 8: Import the following namespaces and type the following code:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
@Override
public void onAnimationEnd(Animation animation) {
finish();
Intent i=new Intent(getBaseContext(),MainActivity.class);
startActivity(i);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
}
Step 9: Create a new folder say “Anim” under resources, create rotate.xml file inside anim folder
Step 10: Open rotate.xml file and add the following code.
<rotate
android:duration="5000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"></rotate>
<activity
android:name=".splash"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
OUTPUT :
Procedure:
Step1: Create a new project and give appropriate application name.
Step2: Open Project Explorer window and open the folder say menu.
Step3: The menu folder has a default Menu resource file say menu_main.xml.
Step4: Open a menu_main.xml file which has a default menu built inside it. Include the <item>
tag and its attributes after closing tools tag.
menu_main.xml
<item android:id="@+id/item1"
android:title="item1"/>
<item android:id="@+id/item2"
android:title="item2"/>
<item android:id="@+id/item3"
android:title="item3"/>
Step5: Open MainActivity.java file and Import android.widget.Toast; look for the function
onOptionsItemSelected.
Step6: Remove all the lines in the onOptionsItemSelected function and replace the code.
MainActivity.java
switch (item.getItemId())
{
case R.id.item1:
Toast.makeText(this, "item1 selected", Toast.LENGTH_LONG).show();
return true;
case R.id.item2:
Toast.makeText(this, "item2 selected", Toast.LENGTH_LONG).show();
return true;
case R.id.item3:
Toast.makeText(this, "item3 selected", Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
OUTPUT :
Procedure:
Step1: Create a new project and give appropriate application name.
Step2: Open Project Explorer window and right click the resource folder and create a new folder
by the name raw.
Step3: Copy any two .mp3 files into the raw folder by renaming it has A.mp3 and B.mp3.
Step4: Open content_main.xml file and place two buttons in the layout.
Step5: Open text tab of content_main.xml file and rename the text property of Button1 and
Button2 as "Audio 1" and "Audio 2".
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.view.View.OnClickListener;
import android.widget.Button;
Step7: In MainActivity.java file add the keyword implements onClickListener in the public
class.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
Button button1 = (Button) findViewById(R.id.button);
Button button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
case R.id.button:
resId=R.raw.a;
break;
case R.id.button2:
resId=R.raw.b;
break;
default:
resId=R.raw.a;
break;
}
if (mp!=null)
{
mp.release();
}
mp=MediaPlayer.create(this,resId);
mp.start();
}
OUTPUT :
Procedure:
Step1: Create a new project and give appropriate application name.
Step2: Open content_main.xml file text tab and add the line in <RelativeLayout> tag as last
attribute.
content_main.xml or activity_main.xml
tools:context="{RelativePackage}.${activityClass}"
Step3: Open content_main.xml file design tab and place a TextView control, EditText control
and two Button controls.
MainActivity.java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import android.widget.EditText;
import android.widget.Toast;
Step9: Declare the variables in MainActivity.java file after the public class.
EditText textmsg;
static final int READ_BLOCK_SIZE=100;
textmsg=(EditText)findViewById(R.id.editText1);
while ((charRead=inputRead.read(inputBuffer))>0)
{
String readstring=String.copyValueOf(inputBuffer,0,charRead);
s+=readstring;
inputRead.close();
Toast.makeText(getBaseContext(),s,Toast.LENGTH_SHORT).show();
}
}catch (Exception e)
{
e.printStackTrace();
}
}
}
Step13: Start your Emulator and Run the application.
OUTPUT :
Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project
Step 3: Rename the text of the Text View controls as “Enter First Number” and “Enter Second
Number”
MainActivity.java
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
number1=(EditText) findViewById(R.id.editText);
number2=(EditText) findViewById(R.id.editText2);
Add_button=(Button) findViewById(R.id.button);
result=(TextView) findViewById(R.id.textView);
Add_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double num1=Double.parseDouble(number1.getText().toString());
double num2=Double.parseDouble(number2.getText().toString());
double sum=num1+num2;
result.setText(Double.toString(sum));
}
});
OUTPUT :
Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project
MainActivity.java
import android.view.View;
import android.widget.Button;
sleep(200);
jumpTime +=5;
progress.setProgress(jumpTime);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
};
t.start();
}
OUTPUT :
Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project
Step 2: Prepare your image which you want to show in grid layout and place them in
res→drawable folder
Step 5: Extend your ImageAdapter.java class from BaseAdapter and fill with following code
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.GridView;
GridView gridView=(GridView)findViewById(R.id.gridView);
gridView.setAdapter(new ImageAdapter(this));
OUTPUT :
Procedure:
Step1: Create a new project and give appropriate application name.
Open content_main.xml file or activity_main.xml file and drag and drop ListView control and
PlainText control. Change the attributes values of EditText has given in the following code.
activity_main.xml
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inputSearch"
android:ems="10"
android:hint="Search Products"
android:inputType="textVisiblePassword"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView" />
MainActivity.java
import android.text.Editable;
import android.widget.ArrayAdapter;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.ListView;
MainActivity.java
MainActivity.java
String products[]={"Bangalore","Mangalore","Karnataka","Chennai","Kerala"};
lv=(ListView)findViewById(R.id.list_view);
inputSearch=(EditText)findViewById(R.id.inputSearch);
adapter=new ArrayAdapter<String>(this,R.layout.list_item,R.id.product_name,products);
lv.setAdapter(adapter);
}
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int i, int i1, int i2)
{
MainActivity.this.adapter.getFilter().filter(cs);
}
AndroidManifest,xml
android:windowSoftInputMode="stateHidden"
OUTPUT :
Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project
MainActivity.java
import android.view.View;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
OUTPUT :
12. Create an Android program for different type of animation from the menu
and the selected animation.
Procedure:
Step 1: Create a new project and give appropriate application name.
MainActivity.java
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;
Step 3: After onCreate() function write the function for fade in and blink animation.
Step 4: Drag and drop two Buttons and the Image View control in activity_main.xml and paste a
pic in drawable folder.
Step 5: Change the Button text property as “Fade” for button1 and “Blink” for button2. For the
Image View control give the source of the image.
Step 6: Create an ‘anim’ folder, and inside ‘anim’ folder create xml file by the name
‘myanimation.xml’.
android:fromYScale="0.5"
android:toXScale="3.0"
android:toYScale="3.0"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%">
</scale>
<scale
android:startOffset="5000"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:toXScale="3.0"
android:toYScale="3.0"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%">
</scale>
</set>
OUTPUT :
MainActivity.java
import android.util.Log;
Step 3:After setContentView in onCreate function write the log file for displaying the message.
Log.d("LifeCycle","onCreate Invoked");
OUTPUT :
MainActivity.java
import android.view.View;
import android.view.MotionEvent;
import android.widget.Toast;
import android.widget.TextView;
int no1=15;
int no2=10;
int s;
OUTPUT :
MainActivity.java
import android.view.View;
import android.widget.Button;
import android.net.Uri;
import android.content.Intent;
import android.widget.EditText;
Step 3: Open activity_main.xml file and place your edittext control and button. Change the name
of the button to “Click Here” through text property.
Step 4: In onCreate function declare the variables for textbox and the button.
button.setOnClickListener(new View.OnClickListener() {
});
OUTPUT :