Found 1631 Articles for Android

How to jump to the home screen of the app using a button in android?

Azhar
Updated on 03-Jul-2020 11:25:19

880 Views

This example demonstrates how do I jump to the home screen of the app using a button 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 android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       Button button ... Read More

How to call a method after a delay?

Azhar
Updated on 03-Jul-2020 11:25:53

802 Views

This example demonstrates how do I call method after a delay 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 android.os.Handler; import android.support.v7.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);       Handler handler = new Handler();       handler.postDelayed(new Runnable() ... Read More

How to use a Volley Library to parse a JSON in android App?

Azhar
Updated on 03-Jul-2020 11:26:36

1K+ Views

This example demonstrates how do I use a volley Library to parse a JSON in android app.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 – To create a JsonArray, go to http://myjson.com/ create your own JsonArray, for example, refer the code below.{    "employees": [       {          "firstname": "Niyaz",          "age": 30,          "mail": "niyaz3444@gmail.com" ... Read More

How to check grant permission at run-time in android?

Azhar
Updated on 03-Jul-2020 11:27:09

2K+ Views

This example demonstrates how do I check grant permission at un-time 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 android.Manifest; import android.content.pm.PackageManager; import android.os.Build; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v4.app.ActivityCompat; import android.widget.Toast; public class MainActivity extends AppCompatActivity{    private static final int REQUEST_PERMISSION_CODE = 101;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);     ... Read More

How to create spinner Programmatically from array in Android?

Azhar
Updated on 03-Jul-2020 11:27:41

2K+ Views

This example demonstrates how do I create spinner programmatically from array 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 android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.Spinner; public class MainActivity extends AppCompatActivity {    Spinner spinner;    String colors[] = {"Red", "Blue", "White", "Yellow", "Black", "Green", "Purple", "Orange", "Grey"};    ArrayAdapter spinnerArrayAdapter;    @Override    protected void onCreate(Bundle ... Read More

How to detect end of ScrollView in Android?

Azhar
Updated on 03-Jul-2020 11:28:18

1K+ Views

This example demonstrates how do I detect end of scrollView 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 android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.ViewTreeObserver; import android.webkit.WebView; import android.widget.ScrollView; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnTouchListener,    ViewTreeObserver.OnScrollChangedListener {    ScrollView scrollView;    WebView webView;    @Override ... Read More

How to detect long press in Android?

Azhar
Updated on 03-Jul-2020 11:28:52

1K+ Views

This example demonstrates how do I detect long Press 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 android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    GestureDetector gestureDetector;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       gestureDetector = new GestureDetector(this, new GestureListener());   ... Read More

How to change a textView Style at runtime in android?

Azhar
Updated on 03-Jul-2020 10:11:17

741 Views

This example demonstrates how do I change a textView style in runtime 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 in res/values/styles.xml    bold|italic    #FFFFFF    normal    #C0C0C0

How to send data back to the main Activity in android?

Azhar
Updated on 03-Jul-2020 10:12:13

764 Views

This example demonstrates how do I send data back to the main 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/layout/activity_main.xml.                 Step 3 − Add the following code to src/MainActivity.javaimport android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    private TextView textViewResult;    private EditText editTextNumber1;    private EditText editTextNumber2;   ... Read More

How to use AlarmManager in Android?

Azhar
Updated on 28-Nov-2020 12:03:38

1K+ Views

This example demonstrates how do I use AlarmManager 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 android.app.AlarmManager import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle import android.util.Log import android.widget.Button import android.widget.TimePicker import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() {    lateinit var btnSetAlarm: Button    lateinit ... Read More

Advertisements