Soham Kolhatkar - Assignment 4 - Designing Your User Interface With Views
Soham Kolhatkar - Assignment 4 - Designing Your User Interface With Views
Soham Kolhatkar - Assignment 4 - Designing Your User Interface With Views
SetA1
MainActivity.java
package com.example.contact_view;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
EditText etxtname;
TextView txtsh;
Button btn1;
String[] names= {"Soham","Abhishek","Aditya","Lieke"};
Spinner s1;
ArrayAdapter<String> aa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SetUpAdapter();
SetUpSpinner();
}
switch (s1.getSelectedItem().toString())
{
case "Soham": txtsh.setText("Name: Soham Kolhatkar\n Contact number:
9175024088\n E-mail ID: qwertyu@gmail.com");
break;
case "Abhishek":txtsh.setText("Name: Abhishek Datar\n Contact number:
9856324775\n E-mail ID: asdfghjk@gmail.com");
break;
case "Aditya": txtsh.setText("Name: Aditya Bachal\n Contact number:
87463251055\n E-mail ID: zxcvbnm@gmail.com");
break;
case "Lieke": txtsh.setText("Name: Lieke Martens\n Contact number:
9876543210\n E-mail ID: poiuyt@gmail.com");
break;
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
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:id="@+id/txtshow1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="ExtraText">
<Spinner
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMe
nu"
android:id="@+id/spn1"
android:layout_width="match_parent"
android:layout_height="41dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="0dp"
android:layout_marginBottom="607dp"
android:paddingLeft="20dp"
android:hint="Contact name"
tools:layout_editor_absoluteY="415dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="162dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginBottom="156dp"
android:textColor="@color/black" />
</RelativeLayout>
spinner_layout.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textViewspn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="4dp"
android:layout_marginBottom="7dp"
android:text=""
/>
</RelativeLayout>
OUTPUT:
SetA2
MainActivity.java
package com.example.addspinner;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
makeArray();
setupAdapter();
setupSpinner();
}
private void setupSpinner()
{
sp1 = (Spinner)findViewById(R.id.spinner);
sp1.setAdapter(aa);
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(),sp1.getSelectedItem().toString(),Toast.LENGTH_LON
G).show();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
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"
tools:context=".MainActivity">
<EditText
android:id="@+id/itemlist"
android:layout_width="179dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginStart="109dp"
android:layout_marginTop="116dp"
android:inputType="textPersonName"
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="20dp"
android:layout_marginTop="212dp"
android: > android:text="ADD"
tools:layout_editor_absoluteX="29dp"
tools:layout_editor_absoluteY="125dp" />
<Button
android:id="@+id/del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="212dp"
android:layout_marginEnd="20dp"
android: > android:text="DELETE"
tools:layout_editor_absoluteX="294dp"
tools:layout_editor_absoluteY="125dp" />
<Spinner
android:id="@+id/spinner"
android:layout_width="409dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="291dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="325dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="263dp"
android:layout_marginEnd="18dp"
android:text=""
android:textColor="#FB0000" />
</RelativeLayout>
spinner_layout.xml
</TextView>
OUTPUT:
SetA3
MainActivity.java
package com.example.dateandtime;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.sql.Time;
import java.text.*;
import java.time.Year;
import java.util.Calendar;
activity_main.xml
<Button
android:id="@+id/stime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txttime"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="Set Time" />
<Button
android:id="@+id/sdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txtdate"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:text="Set Date" />
<TextView
android:id="@+id/txttime"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:layout_marginTop="99dp"
android:text=""
android:textSize="16sp"
android:textColor="@color/black"
android:paddingLeft="20dp"
/>
<TextView
android:id="@+id/txtdate"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_below="@+id/stime"
android:layout_centerVertical="true"
android:layout_marginTop="107dp"
android:text=""
android:textSize="16sp"
android:textColor="@color/black"
android:paddingLeft="20dp"
/>
</RelativeLayout>
OUTPUT: