Found 1631 Articles for Android

How to create a Custom Dialog box on Android?

Azhar
Updated on 31-Jul-2019 07:46:12

2K+ Views

This example demonstrates about how do I create a custom message 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 projectStep 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Click res from Project → Right click on layout → Select New → Layout resource file → Name the layout = “ custom_dialog, enter Linear layout in the “Root element” and click okayStep 4 − Add the following code to custom_dialog.xml         ... Read More

How to start new Activity on click button in Android?

Azhar
Updated on 31-Jul-2019 07:34:42

19K+ Views

This example demonstrates about how do I start new Activity on click 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 projectStep 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 {    Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       button = (Button) ... Read More

How to get current date and time from internet in android?

Azhar
Updated on 31-Jul-2019 07:28:32

862 Views

This example demonstrates about how do I get date and time from internet 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 projectStep 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport java.text.SimpleDateFormat; import java.util.Calendar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    Calendar calendar;    SimpleDateFormat simpledateformat;    String Date;    TextView DisplayDateTime;    Button btn;    @Override    protected void ... Read More

How to set the date in datepicker dialog in android?

Azhar
Updated on 01-Aug-2019 07:23:12

1K+ Views

This example demonstrates about how do I set the date in datepicker dialog 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 projectStep 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to res/layout/DatePickerFragment.java (Right click on the package, click new – Java Class)import android.app.DatePickerDialog; import android.app.Dialog; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import java.util.Calendar; public class DatePickerFragment extends DialogFragment {    @NonNull    @Override    public Dialog onCreateDialog(Bundle savedInstanceState) {   ... Read More

How to pass a String from one Activity to another in Android?

Azhar
Updated on 31-Jul-2019 07:15:06

211 Views

This example demonstrates about how do I pass a String from one Activity to another 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 projectStep 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javapackage app.com.sample; import 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; public class MainActivity extends AppCompatActivity {    Button changeActivityButton;    EditText messageEditText;    @Override    protected void onCreate(Bundle savedInstanceState) {       ... Read More

How to change Screen Orientation programmatically using a Button in Android?

Azhar
Updated on 01-Aug-2019 07:21:21

1K+ Views

This example demonstrates about how do I change the Screen Orientation programmatically 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 projectStep 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javapackage app.com.sample; import android.content.pm.ActivityInfo; 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);       ... Read More

Where and how to use to static variables in android studio?

Azhar
Updated on 01-Aug-2019 07:19:46

522 Views

This example demonstrates about how and where do I use static variable in android studio.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new projectStep 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.util.Log; public class MainActivity extends AppCompatActivity {    public static final String TAG = "I'm a Static Variable";    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    } ... Read More

How to load an ImageView by URL on Android using Picasso?

Azhar
Updated on 01-Aug-2019 07:18:59

571 Views

This example demonstrates about how do I load an ImageView on Android using Picasso.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 − Gradle Scripts from Project → Click build.gradle (Module: app) → add dependency − Implementation ‘com.squareup.picasso−Picasso:2.5.2 and click “Sync now”.Step 3 − Add the following code to res/layout/activity_main.xml.             Step 4 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; import com.squareup.picasso.Picasso; public class MainActivity extends AppCompatActivity {    private ImageView ... Read More

How to get the touch position on android device?

Azhar
Updated on 01-Aug-2019 07:17:40

1K+ Views

This example demonstrates about how do I get the touch position on android device.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new projectStep 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.javapackage app.com.sample; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView T;    EditText E1, E2;    float x = 0f;    float y = 0f;   ... Read More

How to call OnDestroy Activity in Android app?

Azhar
Updated on 01-Aug-2019 07:16:37

748 Views

This example demonstrates about How do I call OnDestroy Activity 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 − Add the following code to src/MainActivity.javapackage com.sample.q2; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class MainActivity extends AppCompatActivity {    public static final String MY_TAG = "Destroy";    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       Log.i(MY_TAG, "onCreate"); ... Read More

Advertisements