ProgressBar View, AutoCompleteTextView, TimePicker View, DatePicker View, ListView View,Spinner View
ProgressBar View, AutoCompleteTextView, TimePicker View, DatePicker View, ListView View,Spinner View
ProgressBar View, AutoCompleteTextView, TimePicker View, DatePicker View, ListView View,Spinner View
In this example, we are displaying the progress dialog for dummy file download operation.
Here we are using android.app.ProgressDialog class to show the progress bar. Android ProgressDialog is the
subclass of AlertDialog class.
The ProgressDialog class provides methods to work on progress bar like setProgress(), setMessage(),
setProgressStyle(), setMax(), show() etc. The progress range of Progress Dialog is 0 to 10000.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
2
<TextView
android:id="@+id/idTVHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/idPBLoading"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:gravity="center"
android:padding="10dp"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
<ProgressBar
android:id="@+id/idPBLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/idBtnDisplayProgress"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:visibility="gone" />
3
<Button
android:id="@+id/idBtnDisplayProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:textAllCaps="false" />
</RelativeLayout>
package com.gtappdevelopers.kotlingfgproject;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showProgressBtn = findViewById(R.id.idBtnDisplayProgress);
loadingPB = findViewById(R.id.idPBLoading);
showProgressBtn.setOnClickListener(new View.OnClickListener() {
@Override
if (isProgressVisible) {
// if it is visible we are
// its visibility
loadingPB.setVisibility(View.GONE);
5
isProgressVisible = false;
} else {
isProgressVisible = true;
loadingPB.setVisibility(View.VISIBLE);
});
}
6
AutoCompleteTextView
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
String[] language
={"C","C++","Java",".NET","iPhone","Android","ASP.NET","PHP"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
7
setContentView(R.layout.activity_main);
//Creating the instance of ArrayAdapter containing list
of language names
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.select_dialog_item,language);
//Getting the instance of AutoCompleteTextView
AutoCompleteTextView actv =
(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
actv.setThreshold(1);//will start working from first
character
actv.setAdapter(adapter);//setting the adapter data into
the AutoCompleteTextView
actv.setTextColor(Color.RED);
}
}
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What is your favourite programming
language?"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.032" />
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
8
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="188dp"
android:layout_height="93dp"
android:layout_weight="1"
android:text="AutoCompleteTextView" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
timePicker
import android.widget.TimePicker;
private TimePicker timePicker1;
timePicker1 = (TimePicker) findViewById(R.id.timePicker1);
9
In order to get the time selected by the user on the screen, you will use
1
is24HourView()
2
isEnabled()
3
setCurrentHour(Integer currentHour)
4
setCurrentMinute(Integer currentMinute)
5
setEnabled(boolean enabled)
6
setIs24HourView(Boolean is24HourView)
7
setOnTimeChangedListener(TimePicker.OnTimeChangedListener
onTimeChangedListener)
This method Set the callback that indicates the time has been adjusted by
the user
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
11
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
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());
}
});
}
12
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="102dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:text="" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="Change Time" />
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
13
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp" />
</RelativeLayout>
DatePicker
1 getDayOfMonth()
2 getMonth()
3 getYear()
4 setMaxDate(long maxDate)
5 setMinDate(long minDate)
6 setSpinnersShown(boolean shown)
8 getCalendarView()
9 getFirstDayOfWeek()
<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"
15
android:layout_height="match_parent"
tools:context="example.javatpoint.com.datepicker.MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="102dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:text="" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
16
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp" />
</RelativeLayout>
Activity class
File: MainActivity.java
package example.javatpoint.com.datepicker;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
17
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
DatePicker picker;
Button displayDate;
TextView textview1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview1=(TextView)findViewById(R.id.textView1);
picker=(DatePicker)findViewById(R.id.datePicker);
displayDate=(Button)findViewById(R.id.button1);
displayDate.setOnClickListener(new View.OnClickListener(){
18
@Override
});
builder.append(picker.getDayOfMonth()+"/");
builder.append(picker.getYear());
return builder.toString();
Output:
19