Articles on Trending Technologies

Technical articles with clear explanations and examples

How to read files from assets on Android using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 5K+ Views

This example demonstrates how to read files from assets on Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Right click app >> New >> Folder >> Assets folder. Right click on the assets folder, select New >> file (myText.txt) and your text.Step 4 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.io.IOException import java.io.InputStream class MainActivity : AppCompatActivity() { ...

Read More

How to work with Camera in an Android App using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 5K+ Views

This example demonstrates how to work with Camera in an Android App using Kotlin.Step 1 − Create a new project in Android Studio, go to File ? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.Manifest import android.content.Intent import android.content.pm.PackageManager import android.graphics.Bitmap import android.os.Bundle import android.provider.MediaStore import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat class MainActivity : AppCompatActivity() {    private val cameraRequest = 1888    lateinit var imageView: ImageView    override fun onCreate(savedInstanceState: Bundle?) ...

Read More

How to create animation using XML file in an Android App using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 631 Views

This example demonstrates how to create animation using XML files in an Android App using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.View import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity(), Animation.AnimationListener {    private lateinit var textView: TextView    private lateinit var buttonZoom: Button    private lateinit var buttonBlink: Button   ...

Read More

How to create GridView Layout in an Android App using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 3K+ Views

This example demonstrates how to create GridView Layout in an Android App using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.AdapterView.OnItemClickListener import android.widget.GridView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var gridView: GridView    private var playerNames = arrayOf("Cristiano Ronaldo", "Joao Felix", "Bernado Silva", "Andre    Silve", "Bruno    Fernandez", "William Carvalho", "Nelson Semedo", "Pepe", "Rui Patricio") ...

Read More

How to switch between different Activities in Android using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 9K+ Views

This example demonstrates how to switch between different Activities in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.os.Bundle import android.widget.Button import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val button:Button = findViewById(R.id.btnOpenAct2)       button.setOnClickListener ...

Read More

How to create Tab Layout in an Android App using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 4K+ Views

This example demonstrates how to create Tab Layout in an Android App using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.viewpager.widget.ViewPager import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout.OnTabSelectedListener import com.google.android.material.tabs.TabLayout.TabLayoutOnPageChangeListener class MainActivity : AppCompatActivity() {    lateinit var tabLayout: TabLayout    lateinit var viewPager: ViewPager    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ...

Read More

How to detect if a user is using an Android tablet or a phone using Kotlin?

Azhar
Azhar
Updated on 21-Jul-2020 928 Views

This example demonstrates how to detect if a user is using an Android tablet or a phone using Kotlin.Step 1 − Create a new project in Android Studio, go to File? New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.Context import android.os.Bundle import android.telephony.TelephonyManager import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"   ...

Read More

Reordered Power of 2 in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 19-Jul-2020 354 Views

Suppose we have a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is non-zero. We have to check whether we can do this in a way such that the resulting number is a power of 2. So if the number is like 46, then the answer will be true.To solve this, we will follow these steps −Define a method called count, this will take x as inputret := 0while x is not 0ret := ret + 10 ^ last digit of xx := x / 10return retFrom the main ...

Read More

beta(), betaf() and betal() functions in C++ STL

sudhir sharma
sudhir sharma
Updated on 17-Jul-2020 406 Views

The functions beta(), betaf() and betal() are built-in functions in the standard template library of C++. These functions are used to calculate the beta function of two positive real numbers.The functions beta(), betaf() and betal() are built-in functions in the standard template library of C++. These functions are used to calculate the beta function of two positive real numbers.$B(x, y)=\int_{0}^{1}t^{(x-1)}(1-t)^{(y-1)}dt$beta()The beta() function is used to deal with values of data type double i.e. it accepts the parameter of double type and returns are double value.Syntaxdouble beta(double x, double y)Parametersx is a double value that gives the value of x in ...

Read More

Bayes Theorem for Conditional Probability in C/C++

sudhir sharma
sudhir sharma
Updated on 17-Jul-2020 1K+ Views

Conditional probability denoted by P(A|B) is the probability of occurrence of an event ‘A’ given that event ‘B’ has already occurred.Formula for conditional probability −P(A|B) = P( A⋂B ) / P(B)Bayes’s TheoremIt is the formula that shows the relation between probabilities of occurrences of mutually dependent events i.e. it given the relation between their conditional probabilities.Given an event A and another event B, according to bayes’ theorem, P(A/B) = {P(B/A) * P(A)} / P(B)Lets derive the formula for Bayes’ theorem, For this we will use the formula for conditional probability, P(A|B) = P( A?B ) / P(B) —— 1 P(B|A) ...

Read More
Showing 51961–51970 of 61,299 articles
Advertisements