Set Input Type for Android EditText Programmatically

Azhar
Updated on 07-Jul-2020 11:47:39

265 Views

This example demonstrates how do I set the input type for an Android EditText 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.xml.           Step 3 − Add the following code to src/MainActivity.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.text.InputType; import android.view.View; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    EditText editText;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);     ... Read More

Convert Color Integer to Hex String in Android

Azhar
Updated on 07-Jul-2020 11:44:56

4K+ Views

This example demonstrates how do I 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.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       TextView textView = findViewById(R.id.textView);       int intColor = -16895234;       String hexColor = ... Read More

Load Files from Asset Directory into WebView in Android

Azhar
Updated on 07-Jul-2020 11:44:21

3K+ Views

This example demonstrates how do I load files from asset directory into WebView 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.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.webkit.WebView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       WebView webView = findViewById(R.id.webView);       webView.loadUrl("file:///android_asset/mytext.html"); ... Read More

Create JSON Using JSONObjectBuilder and JSONArrayBuilder in Java

raja
Updated on 07-Jul-2020 11:43:40

10K+ Views

The JsonObjectBuilder can be used for creating JsonObject models whereas the JsonArrayBuilder can be used for creating JsonArray models. The JsonObjectBuilder can be created using the Json class, it contains methods to create the builder object and build an empty JsonObject instance using the Json.createObjectBuilder().build(). The JsonArrayBuilder can be created using the Json class, it contains methods to create the builder object and build an empty JsonArray instance using Json.createArrayBuilder().build().Exampleimport java.io.*; import javax.json.*; public class JsonObjectTest {    public static void main(String[] args) {       JsonObject empObject = Json.createObjectBuilder().add("empName", "Jai")                                  .add("empAge", ... Read More

Hide and Show Menu Item in Android ActionBar

Azhar
Updated on 07-Jul-2020 11:43:04

5K+ Views

This example demonstrates how do I hide and show a menu item in the Android ActionBar.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.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.CompoundButton; import android.widget.ToggleButton; public class MainActivity extends AppCompatActivity {    ToggleButton button1;    Menu myMenu;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);     ... Read More

Override Home Button in Android App

Azhar
Updated on 07-Jul-2020 11:40:42

782 Views

This example demonstrates how do I 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.javaimport androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    }    @Override    protected void onUserLeaveHint(){       Toast.makeText(getApplicationContext(), "Home Button is Pressed", Toast.LENGTH_SHORT).show();       ... Read More

Protect System Data on Public Wi-Fi Network

Samual Sam
Updated on 07-Jul-2020 11:40:02

191 Views

Now these days, technologies are so advance and provide various options to connect to the public Wi-Fi networks, using this user can easily jump to the any place online like; Coffee shops, hotels, restaurants, airports and many-more. It is true, Wi-Fi is easy and flexible to use but, more than that it is insecure whether you are using a laptop, tablet or smartphone. Definitely, people who use Wi-Fi network want secure network to protect their system data as much as possible. So, to protect system data due to Wi-Fi network, this article is providing you some techniques which may resolve ... Read More

Find Maximum and Minimum Element's Position in a List in Java

AmitDiwan
Updated on 07-Jul-2020 09:54:25

399 Views

To find the maximum and minimum element’s position in a list, the Java program is as follows −Example Live Demoimport java.util.*; import java.util.Arrays; import java.util.Collections; public class Demo{    public static int index_val(int my_arr[], int t){       if (my_arr == null){          return -1;       }       int len = my_arr.length;       int i = 0;       while (i < len){          if (my_arr[i] == t){             return i;          } else {         ... Read More

Iterate Over a Stream with Indices in Java 8

AmitDiwan
Updated on 07-Jul-2020 09:52:03

603 Views

To iterate over a Stream with Indices in Java 8, the code is as follows −Example Live Demoimport java.util.stream.IntStream; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; public class Demo{    public static void main(String[] args){       String[] my_array = { "T", "h", "i", "s", "s", "a", "m", "p", "l", "e" };       AtomicInteger my_index = new AtomicInteger();       System.out.println("The elements in the string array are :");       Arrays.stream(my_array).map(str -> my_index.getAndIncrement() + " -> " + str).forEach(System.out::println);    } }OutputThe elements in the string array are : 0 -> T 1 -> h 2 -> i 3 ... Read More

Sort Words of a Sentence in Ascending Order in Java

AmitDiwan
Updated on 07-Jul-2020 09:41:56

5K+ Views

To sort words of sentence in ascending order, the Java code is as follows −Example Live Demoimport java.util.*; public class Demo{    static void sort_elements(String []my_str, int n){       for (int i=1 ;i= 0 && temp.length() < my_str[j].length()){             my_str[j+1] = my_str[j];             j--;          }          my_str[j+1] = temp;       }    }    public static void main(String args[]){       String []my_arr = {"This", "is", "a", "sample"};       int len = my_arr.length;       sort_elements(my_arr,len);       System.out.print("The sorted array is : ");       for (int i=0; i

Advertisements