Use CardView in RecyclerView

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

473 Views

This example demonstrates about How to use cardview in recyclerviewStep 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.                   In the above code, we have taken app bar layout and recycler view.Step 3 − Add the following code to src/MainActivity.java import android.annotation.TargetApi; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.support.v4.content.pm.ShortcutInfoCompat; import android.support.v4.content.pm.ShortcutManagerCompat; import android.support.v4.graphics.drawable.IconCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import ... Read More

Sort a List in Case-Insensitive Order in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

3K+ Views

Let’s say your list is having the following elements −P, W, g, K, H, t, ETherefore, case sensitive order means, capital and small letters will be considered irrespective of case. The output would be −E, g, H, K, P, t, WThe following is our array −String[] arr = new String[] { "P", "W", "g", "K", "H", "t", "E" };Convert the above array to a List −Listlist = Arrays.asList(arr);Now sort the above list in case insensitive order −Collections.sort(list, String.CASE_INSENSITIVE_ORDER);Example Live Demoimport java.util.Arrays; import java.util.Collections; import java.util.List; public class Demo {    public static void main(String[] argv) throws Exception {       ... Read More

Update VARCHAR Column Length in MySQL

George John
Updated on 30-Jul-2019 22:30:25

642 Views

Let us first create a table. Here, we have two columns with varchar type −mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserFirstName varchar(10),    UserLastName varchar(20) ,    UserAge int ); Query OK, 0 rows affected (0.96 sec)Let us check the description of table using DESC command −mysql> desc DemoTable;This will produce the following output −+---------------+-------------+------+-----+---------+----------------+ | Field         | Type        | Null | Key | Default | Extra          | +---------------+-------------+------+-----+---------+----------------+ | UserId        | int(11)     | NO   ... Read More

SecureRandom getAlgorithm Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

158 Views

The name of the algorithm for the SecureRandom object can be obtained using the method getAlgorithm() in the class java.security.SecureRandom. This method requires no parameters and it returns the name of the algorithm for the SecureRandom object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String algorithmName = sRandom.getAlgorithm();          System.out.println("The Algorithm is: " + algorithmName);       } catch (NoSuchAlgorithmException e) { ... Read More

MySQL IF Statement with Multiple Conditions

Samual Sam
Updated on 30-Jul-2019 22:30:25

8K+ Views

You can use if statement in a stored procedure with multiple conditions with the help of AND or OR operator. The syntax is as follows −DECLARE X int; DECLARE Y int; SET X = value1; SET Y = value2; IF ( (X < Y AND X > value1 AND Y >value2) OR X! = anyValueToCompare) THEN    yourStatement; ELSE    yourStatement; END IFNow to understand the above syntax, let us create a stored procedure. The query to create a stored procedure is as follows −mysql> create procedure SP_IFELSEDEMO()    -> BEGIN    -> DECLARE X int;    -> DECLARE Y ... Read More

Refresh JSP Page at Regular Interval

Chandu yadav
Updated on 30-Jul-2019 22:30:25

334 Views

Following example would use setIntHeader() method to set Refresh header to simulate a digital clock −           Auto Refresh Header Example                        Auto Refresh Header Example                 Now put the above code in main.jsp and try to access it. This will display the current system time after every 5 seconds as follows. Run the JSP. You will receive the following output: −Auto Refresh Header ExampleCurrent Time is: 9:44:50 PM

Check Database Support for Batch Processing

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

296 Views

Not all the databases support batch processing therefore before proceeding with batch updates in your application. You need to verify whether the database you are trying to communicate supports batch processing/batch updates or not.You can do so using the supportsBatchUpdates() method of the DatabaseMetaData interface.Follow the steps given below:Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as a parameter.Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create a DatabaseMetaData object using the getMetaData() method of ... Read More

Use COUNT in Android SQLite

Nitya Raut
Updated on 30-Jul-2019 22:30:25

965 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to use COUNT () in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

Generate Infinite Stream of Double in Java Using DoubleStream.generate

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

117 Views

The DoubleStream.generate() method returns an infinite sequential unordered stream where each element is generated by the provided DoubleSupplier.The syntax is as follows −static DoubleStream generate(DoubleSupplier s)Here, s is the DoubleSupplier for generated elements. The DoubleSupplier represents a supplier of double-valued results.To use the DoubleStream class in Java, import the following package −import java.util.stream.DoubleStream;The following is an example to generate Infinite stream of Double in Java with DoubleStream.generate() method −Exampleimport java.util.stream.*; import java.util.*; public class Demo {    public static void main(String[] args) {       Random r = new Random();       DoubleStream.generate(r::nextDouble).forEach(System.out::println);    } }Here is ... Read More

Convert Value to String Using toString in MongoDB

Anvi Jain
Updated on 30-Jul-2019 22:30:25

2K+ Views

Let us see an example to understand the $toString in MongoDB. To understand the above concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.objectidToStringDemo.insertOne({"UserName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92b80036de59bd9de0639d") } > db.objectidToStringDemo.insertOne({"UserName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92b80436de59bd9de0639e") } > db.objectidToStringDemo.insertOne({"UserName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92b80936de59bd9de0639f") } > db.objectidToStringDemo.insertOne({"UserName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92b81836de59bd9de063a0") }Display all documents from a collection with the help of find() method. The query is as follows ... Read More

Advertisements