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

Code Ex

The document contains multiple examples of Android application code, including user interface elements like EditText, TextView, Button, and Spinner. It demonstrates how to handle user input, pass data between activities using Intent and Bundle, and draw graphics on a Canvas. Additionally, it includes a resource file for string definitions used in the app.

Uploaded by

divyafinalit
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 views44 pages

Code Ex

The document contains multiple examples of Android application code, including user interface elements like EditText, TextView, Button, and Spinner. It demonstrates how to handle user input, pass data between activities using Intent and Bundle, and draw graphics on a Canvas. Additionally, it includes a resource file for string definitions used in the app.

Uploaded by

divyafinalit
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

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

}
}

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

}
Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}
Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

}
Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}
Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

}
Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}
[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;
TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;
e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>
Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);
[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {


[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);
[Link](50);

});

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});
}

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

}
Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});
}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

}
Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}
Ex No: 1

EditText e1;

TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

}
Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}
[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;
TextView t1;

Button b1;

e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>

Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Ex No: 1

EditText e1;

TextView t1;

Button b1;
e1=findViewById([Link].n1);

t1=findViewById([Link].t1);

b1=findViewById([Link].b1);

[Link](new [Link]() {

@Override

public void onClick(View v) {

[Link]([Link]().toString());

[Link]([Link]);

[Link](50);

});

Ex 2:

Main [Link]
EditText e1;
Button b1;
Spinner s1;
e1=findViewById([Link].e2);
b1=findViewById([Link].b2);
s1=findViewById([Link]);
[Link](new [Link](){
public void onClick(View v){
Bundle b=new Bundle();
Intent i=new Intent([Link],[Link]);
[Link]("name",[Link]().toString());
[Link]("dept",[Link]().toString());
[Link](b);
startActivity(i);
}
});

}
}
Main Activity 2 .java

TextView t1,t2;
t1=findViewById([Link].t3);
t2=findViewById([Link].t4);
Bundle b=getIntent().getExtras();
[Link]([Link]("name"));
[Link]([Link]("dept"));
Button b1=findViewById([Link].b3);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent i = new Intent([Link], [Link]);
startActivity(i);
}
});
}
}

[Link]
<resources>
<string name="app_name">My Application</string>
<string-array name="dept">
<item>CSE</item>
<item>IT</item>
</string-array>
</resources>
Ex3:
Bitmap bg=[Link](720,1280,[Link].ARGB_8888);
ImageView i=(ImageView)findViewById([Link]);
Button b=(Button)findViewById([Link]);
Canvas c=new Canvas(bg);
Paint p=new Paint();
[Link](bg);
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]([Link]);
[Link](35);
[Link]("Rectangle", 150, 350, p);
[Link](150, 150, 300, 300, p);
[Link]([Link]);
[Link](200,100,50,p);
[Link]([Link]);
[Link](150,150,225,75,p);
[Link](225,75,300,150,p);
}
});

}
}

Common questions

Powered by AI

Using setTextColor(Color.BLUE) changes the text color to blue, which can improve readability and ensure differentiation from the default color, contributing to a visually appealing interface. However, setting the text size to 50 can make the text excessively large, potentially leading to text overflow or requiring additional space on smaller screens, which could negatively affect user experience if not properly handled .

The 'String.xml' file is used to define string resources such as the application name and an array of department names. These resources are referenced in the Java code using their resource IDs when needed, allowing for easier localization and management of the text displayed in the application .

Intents are necessary in this architecture to facilitate the transition between activities while passing data. They allow the MainActivity to send user-input data, collected through EditText and Spinner, to MainActivity2 via Bundles. This ensures the user inputs are accessible in the new activity to update TextViews accordingly .

To ensure better data validation, input checks should be implemented before calling startActivity. For instance, checking if the EditText field is not empty and Spinner has a selected item could prevent empty or null data from being passed. Implementing try-catch blocks could handle exceptions, and using Toast messages can inform the user of any input errors, enhancing reliability and user feedback .

findViewById is used to get a reference to a view defined in the XML layout file. setOnClickListener is used to set an action that should occur when the Button is clicked. setText is used to set the text property of a TextView or EditText .

The elements drawn on the Canvas become visible by first creating a Bitmap and setting it as the source image of an ImageView using setImageBitmap(). The Canvas is then associated with this Bitmap, and when drawing methods like drawText, drawRect, drawCircle are called, the drawn content is rendered onto the Bitmap, making it visible on the ImageView .

In MainActivity2, the Button b1 is used to navigate the user back to MainActivity. When clicked, it creates a new Intent targeting MainActivity and calls startActivity(i), effectively sending the user back to the previous activity .

ARGB_8888 configuration provides 8 bits for alpha, red, green, and blue channels, which offers high image quality with transparency support. It is chosen for rendering precision and quality. Alternatives like RGB_565 use less memory and offer faster performance but do not support transparency, possibly sacrificing image detail quality .

Graphical elements such as a red rectangle, a green circle, and blue lines forming a triangle are drawn on the Canvas. This is achieved by creating a Bitmap and setting it as the ImageView's content. A Paint object is then used to draw the text 'Rectangle' and the shapes onto the Canvas at specified coordinates using drawText, drawRect, drawCircle, and drawLine methods .

Data is passed from MainActivity to MainActivity2 using a Bundle attached to an Intent. The EditText value is fetched and added to the Bundle with a key 'name', and the selected item from the Spinner is added with the key 'dept'. These are then put into the Intent using putExtras and passed on with startActivity().

You might also like