0% found this document useful (0 votes)
16 views

Practical 14

The document contains a series of exercises related to mobile application development, including XML and Java code examples for creating various user interface components such as ListView, ImageView, GridView, and ScrollView. Each exercise provides the necessary code snippets and describes the intended output for the applications. The exercises aim to enhance understanding of Android development practices and UI design.

Uploaded by

sainathkorpakwad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Practical 14

The document contains a series of exercises related to mobile application development, including XML and Java code examples for creating various user interface components such as ListView, ImageView, GridView, and ScrollView. Each exercise provides the necessary code snippets and describes the intended output for the applications. The exercises aim to enhance understanding of Android development practices and UI design.

Uploaded by

sainathkorpakwad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Subject :- Mobile Application Development Subject Code :- 22617

Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24

Exercise :-

1). Write a program to show the following output. Use appropriate view for the same.

Code :-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.co m/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent”
android:entries="@array/Language_list”
/>
</RelativeLayout>
strings.xml
<resources>
<string name="app_name">
Exp14_1
</string>
<array name="Language_list">
<item>Android</item>
<item>Java</item>
<item>PHP</item>
<item>Hadoop</item>
<item>Sap</item>
<item>Phython</item>
<item>Ajax</item>
<item>C++</item>
<item>Puby</item>
<item>Rails</item>
</array>
</resources>
Java Code
package com.example.exp14_1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Output :-
2). Write a program to display an image using Image View and a button named as
“ Chang Button”. Once you click on button another image should get displayed.
Code :-
XML Code:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/img_1" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="Change Image" />
</LinearLayout>
Java Code:
package com.example.pr14;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View; import
android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity
{
Button bt;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = findViewById(R.id.button);
img = findViewById(R.id.imageView);
bt.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
img.setImageResource(R.drawable.img);
}
});
}
}

Output :-
3). Write a program to display 15 buttons using grid view.
Code :-
Xml Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<GridView
android:id="@+id/g1"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp"
android:numColumns="3"/>
</LinearLayout>
java Code:
package com.example.lec4;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gv = (GridView) findViewById(R.id.g1);
String s1[] ={"EDE", "BEC" , "PWP", "WBP" , "OSY" , "MAD" , "STE" , "EST" , "CSS" , "CPH", "abc" ,
"def" , "efg" , "xyz", "tty", "def" , "efg" , "xyz", "tty"};
ArrayAdapter ad = new ArrayAdapter(this, androidx.appcompat.R.layout.support_simple_
spinner_dropdown_item,s1);

gv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Toast.makeText(MainActivity.this,"You have clicked: "+s1[position],Toast.LENGTH_SHORT).show();
}
});
gv.setAdapter(ad);
}
}

Output :-
4). Write a program to display text view using vertical scroll view.
Code :-
XML Code:

<?xml version= "1.0" encoding= "utf-8" ?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Vertical ScrollView example In computer displays, filmmaking, television production, and
other kinetic displays, scrolling is sliding text, images or video across a monitor or display, vertically or
horizontally.Scrolling ,as such, does not change the layout of the text or pictures but moves (pans or tilts)
the user's view across what is \n apparently a larger image that is not wholly seen.[1] A common
television and movie special effect is to scroll credits, \n while leaving the background stationary.
Scrolling may take place completely without user intervention (as in film credits) \n or, on an interactive
device, be triggered by touchscreen or a keypress and continue without further intervention until a \n
further user action, or be entirely controlled by input devices. Scrolling may take place in discrete
increments \n (perhaps one or a few lines of text at a time), or continuously (smooth scrolling). Frame
rate is the speed at which an \n entire image is redisplayed. It is related to scrolling in that changes to
text and image position can only happen as often \n as the image can be redisplayed. When frame rate
is a limiting factor, one smooth scrolling technique is to blur images during \n movement that would
otherwise appear to jump \n Scrolling texts, also referred to as scroll texts or scrollers, played an
important part in the birth of the computer demo culture. The software crackers often used their deep
knowledge of computer platforms to transform the information that accompanied their releases
into crack intros. The sole role of these intros was to scroll the text on the screen in an impressive way.
Many scrollers were plain horizontal scrollers, but demo coders also paid a lot of attention to creating
new and different types of scrolling.The characters could, for example, continuously alter their shape,
take unusual flying paths or incorporate color effects such as raster bars.Sometimes it makes the text
nearly unreadable." />
</ScrollView>
</RelativeLayout>

Output :-

You might also like