Change Background Color of ListView Items on Android

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

2K+ Views

This example demonstrate about How to change the background color of ListView items on Android.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.     Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.sample ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.AdapterView ; import android.widget.ArrayAdapter ; import android.widget.ListView ; public class MainActivity extends AppCompatActivity {    String[] mobileArray = { "Android" , "IPhone" , "WindowsMobile" , "Blackberry" ,   ... Read More

Find Exact Match in Array Without Using $elemMatch Operator in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:26

325 Views

As an alternative, use the $eq operator. Let us first create a collection with documents −> db.equalDemo.insertOne({_id:1, "StudentFriendNames":["John", "Carol", "Sam"]}); { "acknowledged" : true, "insertedId" : 1 } > db.equalDemo.insertOne({_id:2, "StudentFriendNames":null}); { "acknowledged" : true, "insertedId" : 2 } > db.equalDemo.insertOne({_id:3, "StudentFriendNames":["Carol"]}); { "acknowledged" : true, "insertedId" : 3 } > db.equalDemo.insertOne({_id:4, "StudentFriendNames":["Sam"]}); { "acknowledged" : true, "insertedId" : 4 }Following is the query to display all documents from a collection with the help of find() method −> db.equalDemo.find();This will produce the following output −{ "_id" : 1, "StudentFriendNames" : [ "John", "Carol", "Sam" ] } { "_id" : 2, ... Read More

Retrieve MySQL Database Structure Information from Java

Sharon Christine
Updated on 30-Jul-2019 22:30:26

469 Views

Use DatabaseMetaData class to retrieve MySQL database structure. In this example, we will display all the table names of database “web” using Java with the help of getMetaData().Following is the Java code −Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import com.mysql.jdbc.DatabaseMetaData; public class getDatabaseInformationDemo {    public static void main(String[] args) {       Connection con = null;       try {          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?useSSL=false", "root", "123456");          DatabaseMetaData information = (DatabaseMetaData) con.getMetaData();          String allTableName[] = {             "TABLE"   ... Read More

HTML DOM Input URL Name Property

AmitDiwan
Updated on 30-Jul-2019 22:30:26

111 Views

The HTML DOM Input URL name property returns a string, which is the value of the name property of input URL. User can also set it to a new string.SyntaxFollowing is the syntax −Returning string valueinputURLObject.nameSetting name attribute to a string valueinputURLObject.name = ‘String’ExampleLet us see an example of Input URL name property − Live Demo Input URL name    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       ... Read More

Add Tooltip to JLabel in Java

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

1K+ Views

Tooltip is visible whenever you will place the mouse cursor on the label. Use the setToolTipText() method to add tooltip to JLabel −label.setToolTipText("This is a demo tooltip");The following is an example to add tooltip to JLabel −Exampleimport java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("Demo Label!");       label.setFont(new Font("Verdana", Font.PLAIN, 14));       label.setToolTipText("This is a demo tooltip");       Border border = BorderFactory.createLineBorder(Color.ORANGE);     ... Read More

Java Equivalent to MySQL's SMALLINT

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

2K+ Views

The short is equivalent to MySQL’s small int. The Java short takes 2 bytes that has the range -32768 to 32767 while MySQL smallint also take 2 bytes with same range.Here is the demo code of short in Java −public class SmallIntAsShortDemo {    public static void main(String[] args) {       short value = 32767;       System.out.println(value);       value = -32768;       System.out.println(value);       // value = 32768;       // System.out.println(value);    } }The snapshot is as follows −This will produce the following output −32767 -32768Here is the snapshot of the output we ran in EclipseIDE −The MySQL smallint takes 2 bytes with same range.

Run a Timer in Background within Your iOS App

Smita Kapse
Updated on 30-Jul-2019 22:30:26

1K+ Views

If you wish to run a timer in background within your iOS Application, Apple provides beginBackgroundTaskWithExpirationHandler method, you can read more about the same developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiration.We will be using the same for writing our code for running the timer in background.So let’s begin.Step 1 − Open Xcode → Single View Application → Let’s name is BackgroundTimer.Step 2 − Open AppDelegate.swift and under method applicationDidEnterBackground write the below code.backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: {    UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier!) }) _ = Timer.scheduledTimer(timeInterval: 1,  target: self,  selector: #selector(self.doSomething), userInfo: nil, repeats: true)Step 3 − Write new function doSomething()@objc func doSomething() {    print("I'm running") }Finally your code should look like belowfunc applicationDidEnterBackground(_ application: UIApplication) {    backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: { ... Read More

Create Empty Border with BorderFactory Class in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:26

586 Views

To create empty border, use the createEmptyBorder() method. Let us first create a label component −JLabel label = new JLabel("Label with empty border!");Now, create empty border with BorderFactory class −label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));The following is an example to create empty border −Examplepackage my; import javax.swing.BorderFactory; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("Label with empty border!");       label.setFont(new Font("Verdana", Font.PLAIN, 16));       label.setVerticalAlignment(JLabel.BOTTOM);     ... Read More

Use Regex in MongoDB

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

300 Views

Following is the syntax to use $regex in MongoDB −db.yourCollectionName.find({yourFieldName: { $regex: yourValue}});Let us first create a collection with documents −> db.regularExpressionDemo.insertOne({"UserName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc25bf3115999ed51210") } > db.regularExpressionDemo.insertOne({"UserName":"JOHN"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc2ebf3115999ed51211") } > db.regularExpressionDemo.insertOne({"UserName":"john"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc35bf3115999ed51212") } > db.regularExpressionDemo.insertOne({"UserName":"JoHn"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc3ebf3115999ed51213") }Following is the query to display all documents from a collection with the help of find() method −> db.regularExpressionDemo.find();This will produce the following output −{ "_id" : ObjectId("5cdffc25bf3115999ed51210"), "UserName" : "John" } { ... Read More

HTML Button Type Attribute

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

156 Views

The type attribute of the element is used to set type of the button. Following is the syntax −Above, we have shown the different types set for the button element i.e.: submit −button: A clickable buttonsubmit: Submit button (submits form-data)reset: It is a reset button to reset it to the initial value.Let us now see an example to implement the type attribute of the button element in HTML −Example Live Demo Investor Information Give the information about the investor interested in funding: ID: Investor: Funds: ... Read More

Advertisements