Working with RecyclerView in an Android App Using Kotlin

Azhar
Updated on 21-Jul-2020 08:59:55

4K+ Views

This example demonstrates how to Work with RecyclerView 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.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() {    private val movieList = ArrayList()    private lateinit var moviesAdapter: MoviesAdapter    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       ... Read More

Encode N-ary Tree to Binary Tree in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:57:15

600 Views

Suppose we have a N-ary tree. We have to encode that tree into one binary. We also have to make deserializer to deserialize the binary tree to N-ary tree.So, if the input is likethen the output will beTo solve this, we will follow these steps −Define a function encode(), this will take root, if root is valid, then −return nullnode = new tree node with value of rootif size of children of root is not 0, then −left of node := encode(children[0] of root)curr = left of nodefor initialize i := 1, when i < size of children of root, ... Read More

Serialize and Deserialize N-ary Tree in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:53:52

427 Views

Suppose we have one N-ary tree and we have to serialize and deserialize them. As we know that the serialization is the process of converting a data structure or object into a sequence of bits so we can store them in a file or memory buffer, and that can be reconstructed later in the same or another computer environment.Here we have to devise an algorithm to serialize and deserialize an N-ary tree. The N-ary tree is a rooted tree in which each node has no more than N children.So, if the input is likethen the output will be Serialize: 1 ... Read More

Work with Camera in Android App Using Kotlin

Azhar
Updated on 21-Jul-2020 08:53:38

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

Word Squares in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:49:06

330 Views

Suppose we have a set of words (all are unique), we have to find all word squares and we can build from them. Here a sequence of words forms a valid word square if the kth row and column read the exact same string, where 0 ≤ k < maximum of numRows and numColumns. So as an example, the word sequence ["ball", "area", "lead", "lady"] will construct a word square because each word reads the same both horizontally and vertically.ballarealeadladySo, if the input is like ["area", "lead", "wall", "lady", "ball"], then the output will be [[ "wall", "area", "lead", "lady"], ... Read More

Perfect Rectangle in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:46:27

275 Views

Suppose we have N axis-aligned rectangles, we have to check whether they all together form an exact cover of a rectangular region or not. Here each rectangle is represented as a bottom-left point and a top-right point. So a unit square is represented as [1, 1, 2, 2]. (bottom-left point is (1, 1) and top-right point is (2, 2)).So, if the input is like rectangles = [[1, 1, 3, 3], [3, 1, 4, 2], [3, 2, 4, 4], [1, 3, 2, 4], [2, 3, 3, 4]], then the output will be true as all 5 rectangles together form an exact ... Read More

Minimum Unique Word Abbreviation in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:45:17

318 Views

Suppose we have a string such as "word" and that contains the following abbreviations: ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]. We also have a target string and a set of strings in a dictionary, we have to find an abbreviation of this target string with the smallest possible length such that it does not conflict with abbreviations of the strings in the dictionary. Here each number or letter in the abbreviation is considered as length = 1. So as an example, the abbreviation "a32bc" is of length = 4.So, if ... Read More

Create Animation Using XML File in Android App with Kotlin

Azhar
Updated on 21-Jul-2020 08:39:40

402 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

Rearrange String K Distance Apart in C++

Arnab Chakraborty
Updated on 21-Jul-2020 08:36:50

594 Views

Suppose we have a non-empty string s and an integer k; we have to rearrange the string such that the same characters are at least distance k from each other. Given strings are in lowercase letters. If there is no way to rearrange the strings, then we will an empty string.So, if the input is like s = "aabbcc", k = 3, then the output will be "abcabc" this is because same letters are at least distance 3 from each other.To solve this, we will follow these steps −ret := an empty stringDefine one map mn := size of sfor ... Read More

Create GridView Layout in an Android App Using Kotlin

Azhar
Updated on 21-Jul-2020 08:32:37

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

Advertisements