Q6.Create A Simple File Chooser in Android
Q6.Create A Simple File Chooser in Android
builder1.setPositiveButton(
"Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder1.setNegativeButton(
"No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
}
}
Output:
Q10.Android ToggleButton
<?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/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/idTVHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/idTVStatus"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:gravity="center"
android:padding="10dp"
android:text="Toggle Button in Android"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/idTVStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/idBtnToggle"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:gravity="center"
android:padding="10dp"
android:text="Status"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold" />
<ToggleButton
android:id="@+id/idBtnToggle"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:padding="10dp"
android:textAllCaps="true"
android:textColor="@color/black"
android:textOff="Off"
android:textOn="On" />
</RelativeLayout>
package com.gtappdevelopers.kotlingfgproject
import android.os.Bundle
import android.widget.TextView
import android.widget.ToggleButton
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
lateinit var toggleBtn: ToggleButton
lateinit var statusTV: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
toggleBtn = findViewById(R.id.idBtnToggle)
statusTV = findViewById(R.id.idTVStatus)
if (toggleBtn.isChecked) {
statusTV.text = "Toggle Button is On"
} else {
statusTV.text = "Toggle Button is Off"
}
toggleBtn.setOnClickListener {
if (toggleBtn.isChecked) {
statusTV.text = "Toggle Button is On"
} else {
statusTV.text = "Toggle Button is Off"
}
}
}
}
Output:
Q11. Android Switch
<?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/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
</RelativeLayout>
package com.gtappdevelopers.kotlingfgproject
import android.os.Bundle
import android.widget.Switch
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
Q15.Android TextView
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:ignore="HardcodedText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GeeksforGeeks"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Q16.Android EditText
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
tools:ignore="HardcodedText">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
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.321" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:backgroundTint="@color/green_500"
android:text="SUBMIT"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="@+id/editText"
app:layout_constraintTop_toBottomOf="@+id/editText" />
<Button
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:backgroundTint="@color/green_500"
android:text="CANCEL"
android:textColor="@color/green_500"
app:layout_constraintEnd_toStartOf="@+id/button"
app:layout_constraintTop_toBottomOf="@+id/editText" />
</androidx.constraintlayout.widget.ConstraintLayout>
Q17.Text input Layout
<resources>
message.setTextSize(progress + 1);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}Progress
});
}
}
Output:
Q20.Android ProgressBar
<?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/idRLContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<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:text="Progress Bar in Android"
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" />
<Button
android:id="@+id/idBtnDisplayProgress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="20dp"
android:text="Show Progress Bar"
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
class MainActivity : AppCompatActivity() {
lateinit var showProgressBtn: Button
lateinit var loadingPB: ProgressBar
var isProgressVisible = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
showProgressBtn = findViewById(R.id.idBtnDisplayProgress)
loadingPB = findViewById(R.id.idPBLoading)
showProgressBtn.setOnClickListener {
.
if (isProgressVisible) {
showProgressBtn.text = "Show Progress Bar"
loadingPB.visibility = View.GONE
isProgressVisible = false
} else {
isProgressVisible = true
showProgressBtn.text = "Hide Progress Bar"
loadingPB.visibility = View.VISIBLE
}
}
}
}
Output: