Outputs 7

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Practical 14

1)
MainActivity.java

package listview.example.com.listview;  

  

import android.support.v7.app.AppCompatActivity;  

import android.os.Bundle;  

import android.view.View;  

import android.widget.AdapterView;  

import android.widget.ArrayAdapter;  

import android.widget.ListView;  

import android.widget.TextView;  

import android.widget.Toast;  

  

public class MainActivity extends AppCompatActivity {  

    ListView listView;  

    TextView textView;  

    String[] listItem;  

    @Override  

    protected void onCreate(Bundle savedInstanceState) {  

        super.onCreate(savedInstanceState);  

        setContentView(R.layout.activity_main);  

  

        listView=(ListView)findViewById(R.id.listView);  

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

        listItem = getResources().getStringArray(R.array.array_technology);  

        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,  

                android.R.layout.simple_list_item_1, android.R.id.text1, listItem);  

       listView.setAdapter(adapter);  

  

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {  

            @Override  

            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {  

                // TODO Auto-generated method stub  

                String value=adapter.getItem(position);  

                Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show(); 

   }  

         });    }  }  
Activity_main.xml

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

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.om/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="listview.example.com.listview.MainActivity">  

  

    <ListView  

        android:id="@+id/listView"  

        android:layout_width="match_parent"  

        android:layout_height="fill_parent"  

         />  

<android.support.constraint.ConstraintLayout> 

3)
Activity_main.xml
package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
public class MainActivity extends Activity {
GridView gridview;
String arr[] = new String[15];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridview = findViewById(R.id.gridview);
for (int i = 0; i < 15; i++) {
arr[i] = Integer.toString(i + 1);}
ArrayAdapter<String> ad = new ArrayAdapter<String>(this,
R.layout.activity_gridview, R.id.btn, arr);
gridview.setAdapter(ad);
}}
MainActivity.java
package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
public class MainActivity extends Activity {
GridView gridview;
String arr[] = new String[15];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridview = findViewById(R.id.gridview);
for (int i = 0; i < 15; i++) {
arr[i] = Integer.toString(i + 1);}
ArrayAdapter<String> ad = new ArrayAdapter<String>(this,
R.layout.activity_gridview, R.id.btn, arr);
gridview.setAdapter(ad);
}}
activity_gridview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>

4)
Activity_main.xml

<?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 \n
displays, scrolling is sliding text, images or video across a monitor or
display, vertically or horizontally. Scrolling \n,
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 \b
Scrolling texts, also referred to as scrolltexts 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>

MainActivity.java

package com.example.myapplication;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
}}
Practical 15
1)
MainActivity.java

package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btnShow);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Message for you:" +
"you have got mail!", Toast.LENGTH_SHORT).show();
}
});
}
}

activity_main.xml

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/text_view_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="hello world,Toast example" />

<Button
android:id="@+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"/>
</LinearLayout>
2)
activity_main.xml

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Pizza" />

<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="68dp"
android:text="Coffee"/>

<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="108dp"
android:text="Burger" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="184dp"
android:text="Order" />

</RelativeLayout>

MainActivity.java
package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


CheckBox pizza,coffe,burger;
Button buttonOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}
public void addListenerOnButtonClick(){
//Getting instance of CheckBoxes and Button from the activty_main.xml file
pizza=(CheckBox)findViewById(R.id.checkBox);
coffe=(CheckBox)findViewById(R.id.checkBox2);
burger=(CheckBox)findViewById(R.id.checkBox3);
buttonOrder=(Button)findViewById(R.id.button);

//Applying the Listener on the Button click


buttonOrder.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View view) {
int totalamount=0;
StringBuilder result=new StringBuilder();
result.append("Selected Items:");
if(pizza.isChecked()){
result.append("\nPizza 100Rs");
totalamount+=100;
}
if(coffe.isChecked()){
result.append("\nCoffe 50Rs");
totalamount+=50;
}
if(burger.isChecked()){
result.append("\nBurger 120Rs");
totalamount+=120;
}
result.append("\nTotal: ").append(totalamount).append("Rs");
//Displaying the message on the toast
Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
}

});
}
}
Prac no 16.1

Activity_main.xml

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timePicker1"
android:layout_marginTop="10dp"
android:layout_marginLeft="160dp"
android:text="Get Date" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_marginLeft="120dp"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:textSize="18dp"/>
</RelativeLayout>

MainActivity.java

package com.example.myapplication;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MainActivity extends Activity {
TimePicker picker;
Button btnGet;
TextView tvw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvw=(TextView)findViewById(R.id.textView1);
picker=(TimePicker)findViewById(R.id.timePicker1);
picker.setIs24HourView(true);
btnGet=(Button)findViewById(R.id.button1);
btnGet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int hour, minute;
String am_pm;
if (Build.VERSION.SDK_INT >= 23 ){
hour = picker.getHour();
minute = picker.getMinute();
}
else{
hour = picker.getCurrentHour();
minute = picker.getCurrentMinute();
}
if(hour > 12) {
am_pm = "PM";
hour = hour - 12;
}
else
{
am_pm="AM";
}
tvw.setText("Selected Date: "+ hour +":"+ minute+" "+am_pm);
}
});}}
Practical 17
1)
Activity_main.xml

<?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"

android:paddingTop="80dp"

tools:context=".MainActivity">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world"/>

</RelativeLayout>

MainActivity.java

package com.example.myapplication;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Activity:", "Created");
}
@Override
protected void onStart() {
super.onStart();
Log.d("Activity:", "Started");
}
@Override
protected void onResume() {
super.onResume();
Log.d("Activity:", "Resume");
}
@Override
protected void onPause() {
super.onPause();
Log.d("Activity:", "Pause");
}
@Override
protected void onStop() {
super.onStop();
Log.d("Activity:", "Stop");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("Activity:", "Restart");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("Activity:", "Destroy");
}
}

You might also like