Pass Data Between Activities Using Android Bundle

Azhar
Updated on 03-Jul-2020 12:40:01

258 Views

This example demonstrates how to pass data between activities.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 res/layout/activity_second.xml.               Step 4  − Add the following code to src/MainActivity.javapackage com.example.sample; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import ... Read More

Create a Transparent Activity in an Android App

Azhar
Updated on 03-Jul-2020 12:37:06

2K+ Views

This example demonstrates how to create a transparent Activity in 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/values/styles.xml.               #33000000       true       @android:color/transparent       @null       true       @android:style/Animation     Step 3  − Add the following code to res/layout/activity_main.xml.         Step 4  − Add the following code to src/MainActivity.javapackage com.example.transparentactivity; import android.support.v7.app.AppCompatActivity; ... Read More

Declare Global Variables on Android

Azhar
Updated on 03-Jul-2020 12:36:21

2K+ Views

This example demonstrates how to declare global variables in 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 com.example.sample; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView tvEvent;    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       ... Read More

Read Value from String XML in Android

Azhar
Updated on 03-Jul-2020 12:35:28

2K+ Views

This example demonstrates how to read value from string.xml in 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/values/strings.xml    Sample    Test string Step 3  − Add the following code to res/layout/activity_main.xml     Step 4  − Add the following code to src/MainActivity.javapackage com.example.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    } }Step ... Read More

When to Use the pack() Method in Java

raja
Updated on 03-Jul-2020 12:33:28

5K+ Views

The pack() method is defined in Window class in Java and it sizes the frame so that all its contents are at or above their preferred sizes. An alternative to the pack() method is to establish a frame size explicitly by calling the setSize() or setBounds() methods. In general, using the pack() method is preferable to call than setSize() method, since pack leaves the frame layout manager in charge of the frame size and layout managers are good at adjusting to platform dependencies and other factors that affect the component size.Syntaxpublic void pack()Exampleimport java.awt.*; import javax.swing.*; public class PackMethodTest extends JFrame {    public ... Read More

Customise iOS Button to Set Text and Color

Sadiqaadil
Updated on 03-Jul-2020 12:32:40

2K+ Views

In this post we will be seeing how to customise iOS button.So let’s get started.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “CustomiseButton”Step 2− Open Main.storyboard and add a button as shown below. We will customize this buttonThere are two ways to customise this buttonUsing StoryboardStep 1 − Click on the buttonStep 2 − In the right panel, in the attribute inspector you can change the text color, text and background color of the button as shown belowRun the project you will see the customise button as belowNow we will see the ... Read More

Apply Different Borders to JButton in Java

raja
Updated on 03-Jul-2020 12:29:27

5K+ Views

A JButton is a subclass of AbstractButton class and it can be used for adding platform-independent buttons in a Java Swing application. A JButon can generate an ActionListener interface when the user clicking on a button, it can also generate MouseListener when a user can do some actions from the mouse and KeyListener when a user can do some actions from the keyboard.We can set different borders like LineBorder, BevelBorder, EtchcedBorder, EmptyBorder, TitledBorder, etc to JButton using the setBorder() method of JComponent class.Syntaxpublic void setBorder(Border border)Exampleimport javax.swing.*; import java.awt.*; public class JButtonBordersTest extends JFrame {    private JButton button[];    private JPanel panel;    public JButtonBordersTest() {   ... Read More

Set Different Look and Feels to Swing Components in Java

raja
Updated on 03-Jul-2020 12:21:53

2K+ Views

The Java Swing allows us to customize the GUI by changing the look and feel(L&F). The look defines the general appearance of components and the feel defines their behavior. L&Fs are subclasses of the LookAndFeel class and each L&F is identified by its fully qualified class name. By default, the L&F is set to the Swing L&F ( Metal L&F)To set the L&F programmatically, we can call the method setLookAndFeel () of the UIManager class. The call to setLookAndFeel must be done before instantiating any Java Swing class, otherwise, the default Swing L&F will be loaded.Syntaxpublic static void setLookAndFeel(LookAndFeel newLookAndFeel) throws UnsupportedLookAndFeelExceptionExampleimport java.awt.*; import ... Read More

Add Multiple Sub-Panels to the Main Panel in Java

raja
Updated on 03-Jul-2020 12:16:44

4K+ Views

A JPanel is a subclass of JComponent class and it is an invisible component in Java. The FlowLayout is a default layout for a JPanel. We can add most of the components like buttons, text fields, labels, tables, lists, trees,  etc. to a JPanel.We can also add multiple sub-panels to the main panel using the add() method of Container class.Syntaxpublic Component add(Component comp)Exampleimport java.awt.*; import javax.swing.*; public class MultiPanelTest extends JFrame {    private JPanel mainPanel, subPanel1, subPanel2;    public MultiPanelTest() {       setTitle("MultiPanel Test");       mainPanel = new JPanel(); // main panel       mainPanel.setLayout(new GridLayout(3, 1));       mainPanel.add(new JLabel("Main ... Read More

Count Records That Begin With Specific Letters in MySQL

AmitDiwan
Updated on 03-Jul-2020 12:02:02

365 Views

Let us first create a table −mysql> create table DemoTable775 ( FirstName varchar(100) ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable775 values('Adam') ; Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable775 values('Carol'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable775 values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable775 values('Sam'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable775 values('Adan'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select ... Read More

Advertisements