0% found this document useful (0 votes)
304 views5 pages

Arid Agriculture University, Rawalpindi: Mid Exam / Spring 2020 (Paper Duration 48 Hours) To Be Filled by Teacher

This document appears to be a midterm exam for a mobile computing course taken at Pir Mehr Ali Shah Arid Agriculture University in Rawalpindi, Pakistan. It contains 7 multiple choice and short answer questions assessing students' knowledge of mobile app development topics like creating toasts, using setContentView(), and moving data between activities. The exam is out of a total of 12 marks and includes spaces for the teacher and student to fill out details like their names, course information, and marks obtained.
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)
304 views5 pages

Arid Agriculture University, Rawalpindi: Mid Exam / Spring 2020 (Paper Duration 48 Hours) To Be Filled by Teacher

This document appears to be a midterm exam for a mobile computing course taken at Pir Mehr Ali Shah Arid Agriculture University in Rawalpindi, Pakistan. It contains 7 multiple choice and short answer questions assessing students' knowledge of mobile app development topics like creating toasts, using setContentView(), and moving data between activities. The exam is out of a total of 12 marks and includes spaces for the teacher and student to fill out details like their names, course information, and marks obtained.
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
You are on page 1/ 5

Pir Mehr Ali Shah

Arid Agriculture University, Rawalpindi


Office of the controller of Examinations
Mid Exam / Spring 2020 (Paper Duration 48 hours)
To be filled by Teacher

Course No.: CS-471 Course Title: Mobile Computing


Total Marks: 12 Date of Exam: June 16, 2020
Degree: BSIT, BSCS Semester: 6th , 7th Section: A,B
Marks
Q.No. 1 2 3 4 5 6 7 8 9 10 Obtained/
Total Marks
Marks
Obtaine
d
Total Marks in Words:
Name of the teacher: Usman Ahmad
Who taught the course:Signature of teacher / Examiner: Usman Ahmad

To be filled by Student

Registration No.: ………………………………………….……… Name:……………………………………………………..

Answer the following questions.

Q.No.1 (Marks 1)
Write a code to create a toast which displays “Mid Term paper is very easy” by clicking anywhere on
the screen. (Only write specific code, not system generated)

Answer: relativeLayout.setOnTouchListener(new View.OnTouchListener() {


@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(MainActivity.this, "Mid Term paper is very
easy",Toast.LENGTH_SHORT).show();
return true; }});

Q.No.2. (Marks 0.5)


What is the purpose of setContentView() function. Write its parameters.
Answer: We use setContentView because it loads the layout of the activity. OnCreate() runs
when we first start our app and it also triggers the setContentView() in it. It’s parameter is the
some_activity.xml file as R.layout.some_activity corresponding to the acitivity file in which
setContentView is placed.

Q.No.3. Write a code by following steps. (Marks 2)


1. Create 2 check boxes and a button on your desired layout.
2. Get values from checkboxes and show on TextView boxes by clicking on button.
3. Now Create two TextView, and a button named as Swap.
4. Swap values of these two TextViews on ‘Swap’ button click.
(write Specific code only)
Answer: buttonToPrint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text_One = aCheckBox.getText().toString();
text_Two = bCheckBox.getText().toString();

aTextView.setText(text_One);
bTextView.setText(text_Two); }});
buttonToSwap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
first_Text = textViewA.getText().toString();
sec_Text = textViewB.getText().toString();

textViewA.setText(sec_Text);
textViewB.setText(first_Text); }});

Q.No.4. (Marks 1.5)

What is the difference between adapter and adapterView? Give two examples of an adapterView.
(Write specific code only, expand space if require)

Answer: ListView coloursLV = findViewById(R.id.coloursLV);


ArrayList<String> coloursAL = new ArrayList<>();
coloursAL.add("Orange");
ArrayAdapter<String> coloursAA = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, coloursAL);
coloursLV.setAdapter(coloursAA);
Spinner gameSpinner = (Spinner) findViewById(R.id. gameSpinner);
String[] games = { “PUBG”, “FORTNITE”, “SNIPER 3D”};
ArrayAdapter gameArrayAdapter = new
ArrayAdapter(this,android.R.layout.simple_spinner_item, games);
gameArrayAdapter.setDropDownViewResource(android.R.layout. simple_spinner_dropdown
_item);
gameSpinner.setAdapter(gameArrayAdapter);

Q.No.5. (Marks 4)

There are three activities named First.java, Second.java and Third.java. Move a string value
as country code from first activity to second activity. e.g. 0092. Now, On second activity
append country code and operator code. For example, 0092321. Then send this value to
third activity. On third activity, append a seven digit number with this value. e.g.
00923212342345. And now show this resultant string in third activity in the form of toast
(Write Specific code, Expand Space if require)
Answer: Button shiftToSecButton = findViewById(R.id.shiftToSecButton);
shiftToSecButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String countryCode = "0900";
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("countryCode", countryCode);
startActivity(intent); }});

Intent intent = getIntent();


String countryCode = intent.getStringExtra("countryCode");
TextView countryCodeTextView = findViewById(R.id.countryCodeTextView);
countryCodeTextView.setText(countryCode);
Button moveToThirdButton = findViewById(R.id.moveToThirdButton);
moveToThirdButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent1 = new Intent(SecondActivity.this, ThirdActivity.class);
String operatorCode = "aloo_anday";
String appendedCode = countryCode + operatorCode;
intent1.putExtra("appendedCode", appendedCode);
startActivity(intent1); }});

TextView completeCodeTextView = findViewById(R.id.completeCodeTextView);


Intent intent = getIntent();
String appendedCode = intent.getStringExtra("appendedCode");
String extraCode = "--telephone--telephone";
String completeCode = appendedCode + extraCode;
completeCodeTextView.setText(completeCode);
Toast.makeText(this, "" + completeCode, Toast.LENGTH_SHORT).show();

Q.No.6. (Marks 1)

Discuss all the four states of an android activity and draw activity life cycle by hand and
include picture in answer.
Answer:

Q.No.7 Print Your Name 100 times using Java (Marks 2)


(Smartest and Shortest Solution will get higher Marks)

Answer: public class PrintMyName {

public static void main(String[] args) {

for (int i = 0; i < 100; i++) {


System. out. println("Majid");

}}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy