0% found this document useful (0 votes)
152 views7 pages

Develop An Application To Display Analog Time Picker. Also Display The Selected Time. (Write Only - Java File) 4 M Mainactivity - Java

The document discusses developing an Android application with a list view containing 5 items, a grid view arranged in a 4x4 layout, and an image view. It provides the XML layout and Java code to implement each of these views.

Uploaded by

snehatomake05
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)
152 views7 pages

Develop An Application To Display Analog Time Picker. Also Display The Selected Time. (Write Only - Java File) 4 M Mainactivity - Java

The document discusses developing an Android application with a list view containing 5 items, a grid view arranged in a 4x4 layout, and an image view. It provides the XML layout and Java code to implement each of these views.

Uploaded by

snehatomake05
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/ 7

Develop an application to display analog Time Picker.

Also display the selected


time. (Write only . java file)
4M
Ans
MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity
{
TextView textview1;
TimePicker timepicker;
Button changetime;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview1=(TextView)findViewById(R.id.textView1);
timepicker=(TimePicker)findViewById(R.id.timePicker);
//Uncomment the below line of code for 24 hour view
timepicker.setIs24HourView(true);
changetime=(Button)findViewById(R.id.button1);
textview1.setText(getCurrentTime());
changetime.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
textview1.setText(getCurrentTime());
}
});
}
public String getCurrentTime()
{
String currentTime="Current Time:
"+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinute();
return currentTime;
}
}

Develop an android application using radio button.


4 M {2M XML FILE & 2M JAVA FILE}
Ans
[Consider any relevant example of Radio Button and in XML file, consider
minimum attributes]
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:padding="30dp"
tools:context=".frame">

<TextView android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button"
android:textSize="20dp"
android:gravity="center"
android:textColor="#f00"/>

<RadioGroup android:id="@+id/group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text1">

<RadioButton android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"/>

<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/male"
android:text="Female"/>
</RadioGroup>

<Button android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/group"
android:layout_marginTop="99dp"
android:layout_centerHorizontal="true"
android:text="Submit" />
</RelativeLayout>
Java File:
package com.example.ifcdiv;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
public class frame extends AppCompatActivity
{
RadioButton male,female;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame);
male=findViewById(R.id.male);
female=findViewById(R.id.female);
b1=findViewById(R.id.submit);
b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String selected; if(male.isChecked())
{
selected="You selected"+male.getText();
}
else
{
selected="You Selected"+female.getText();
}
Toast.makeText(getApplicationContext(),selected,Toast.LENGTH_LONG).show();
}
});
}
}

Write a program to display a rectangular progress bar.


4 M (xml file 2M, java file 2 )
Ans
Xml File:
<?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">
<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar"
android:layout_below="@+id/progressBar"/>
</RelativeLayout>

Java file:
package in.edu.vpt.progressbar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
{
private ProgressBar progressBar;
private int progressStatus = 0;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
textView = (TextView) findViewById(R.id.textView);
// Start long running operation in a background thread
new Thread(new Runnable()
{
public void run()
{
while (progressStatus < 100)
{
progressStatus += 1;
new Handler(Looper.getMainLooper()).post(new Runnable()
{
public void run()
{
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
try
{
// Sleep for 200 milliseconds.
Thread.sleep(200);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}).start();
}
}

Develop a program to implement


i)
List view of 5 items
ii)
Grid view of 4 x 4 items
iii)
Image view.

Ans:

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<ListView
android:id="@+id/sample_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

<GridView
android:id="@+id/gridview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="50dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>

<ImageView
android:id="@+id/full_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/android_logo" />
</LinearLayout>

Placed image that has to be displayed in drawable folder

package in.msbte.controls_exam_ques;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity
{
String[] sampleArray = {"Item 1","Item 2","Item 3","Item 4", "Item 5"};
GridView gridView;
static final String[] alphabets = new String[]
{
"A", "B", "C", "D", "E",
"F", "G", "H", "I", "J",
"K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"
};
ArrayAdapter adapter, adapter1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//List View
adapter = new ArrayAdapter<String>(this, R.layout.simple_item, sampleArray);
ListView listView = (ListView) findViewById(R.id.sample_list);
listView.setAdapter(adapter);
//Grid View
gridView = (GridView) findViewById(R.id.gridview1);
adapter1 = new ArrayAdapter<String>(this, R.layout.simple_item, alphabets);
gridView.setAdapter(adapter1);
}
}

You might also like