Practical 14
Practical 14
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:
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:
Output :-