Get Resource ID of an Image by Name in Android

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

3K+ Views

This example demonstrate about How do I get the resource id of an image if I know its name in AndroidStep 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.java         Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.sample ; import android.os.Bundle ; import android.support.v7.app.AppCompatActivity ; import android.util.Log ; import android.widget.TextView ; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate (Bundle savedInstanceState) {       ... Read More

Removing Empty Fields from MongoDB

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

486 Views

To remove empty fields, use deleteMany(). Let us first create a collection with documents −> db.removeEmptyFieldsDemo.insertOne({"StudentName":""}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92b9578f00858fb12e919") } > db.removeEmptyFieldsDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92b9878f00858fb12e91a") } > db.removeEmptyFieldsDemo.insertOne({"StudentName":""}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92b9c78f00858fb12e91b") } > db.removeEmptyFieldsDemo.insertOne({"StudentName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92ba078f00858fb12e91c") }Following is the query to display all documents from a collection with the help of find() method −> db.removeEmptyFieldsDemo.find();This will produce the following output −{ "_id" : ObjectId("5ce92b9578f00858fb12e919"), "StudentName" : "" } { "_id" : ObjectId("5ce92b9878f00858fb12e91a"), "StudentName" : "Chris" ... Read More

Display Grant Defined for a MySQL User

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

204 Views

Use SHOW GRANTS for this. Following is the syntax −SHOW GRANTS FOR 'yourUserName'@'yourHostName';Let us display the user name and host name from MySQL.user table.mysql> select user, host from MySQL.user;This will produce the following output −+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Charlie | % ... Read More

HTML DOM Input Week Form Property

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

122 Views

The HTML DOM Input Week form property returns the reference of enclosing form for input Week.SyntaxFollowing is the syntax −Returning reference to the form objectinputWeekObject.formExampleLet us see an example for Input Week form property − Live Demo Input Week form    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    } Week-form Examination Week: ... Read More

Fill or Pad a Column with Zeros Using a MySQL Query

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

497 Views

You can use ZEROFILL for column to fill in or pad with zeros. Let us first create a table−mysql> create table DemoTable    (    Number int    ); Query OK, 0 rows affected (0.58 sec)Following is the query to add zerofill attribute for Number column−mysql> alter table DemoTable change Number Number int(10) zerofill not null; Query OK, 0 rows affected (1.13 sec) Records: 0 Duplicates: 0 Warnings: 0Insert records in the table using insert command −mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(12); Query OK, 1 row affected (0.53 sec) ... Read More

Use MySQL CASE Statement in UPDATE Query

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

868 Views

For using MySQL CASE statement while using UPDATE Query, you can use CASE statement. Let us first create a table −mysql> create table DemoTable    (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserScore int    ); Query OK, 0 rows affected (0.29 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(UserScore) values(100); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(UserScore) values(110); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(UserScore) values(120); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable(UserScore) values(200); Query OK, 1 ... Read More

Return Next Node in a JTree with Java

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

223 Views

Use the getNextNode() method to get the next node after this node in Java. Here, we are displaying the next node of child node “eight” -System.out.println("Next node after this node = "+eight.getNextNode());The following is an example to return the next node after this node in a JTree -Examplepackage my; import javax.swing.JFrame; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       DefaultMutableTreeNode node = new DefaultMutableTreeNode("Products");       DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("Clothing (Product1 - P66778)");       DefaultMutableTreeNode node2 ... Read More

Set Margins in an Android LinearLayout Programmatically

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

5K+ Views

This example demonstrate about How to set margins in an Android LinearLayout programmatically.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.java Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.sample ; import android.os.Bundle ; import android.support.v7.app.AppCompatActivity ; import android.widget.Button ; import android.widget.LinearLayout ; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate (Bundle savedInstanceState) {       super .onCreate(savedInstanceState) ;       setContentView(R.layout. activity_main ) ;       ... Read More

Convert a Field to an Array Using MongoDB Update Operation

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

1K+ Views

To convert a field to an array, use $set operator. Let us first create a collection with documents −> db.convertAFieldToAnArrayDemo.insertOne({"StudentSubject":"MongoDB"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce92d7778f00858fb12e91d") }Following is the query to display all documents from a collection with the help of find() method −> db.convertAFieldToAnArrayDemo.find();This will produce the following output −{ "_id" : ObjectId("5ce92d7778f00858fb12e91d"), "StudentSubject" : "MongoDB" }Following is the query to convert a field to an array using update operation with $set:−> db.convertAFieldToAnArrayDemo.find().forEach(function(myDocument) {    db.convertAFieldToAnArrayDemo.update(       { _id: myDocument._id },       { "$set": { "StudentSubject": [myDocument.StudentSubject] } }    ); })Let ... Read More

Split Column After Hyphen in MySQL

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

704 Views

To split a column after hyphen, use the SUBSTRING_INDEX() method −select substring_index(yourColumnName, '-', -1) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable -> ( -> StreetName text -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Paris Hill St.-CA-83745646') ; Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('502 South Armstrong Street-9948443'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from ... Read More

Advertisements