Found 1631 Articles for Android

How to set OnclickListener on a radio button in android?

Azhar
Updated on 03-Jul-2020 05:56:54

2K+ Views

This example demonstrates how do I set OnclickListener on a radio 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.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);    } ... Read More

How can I use Marquee text in an android app?

Azhar
Updated on 03-Jul-2020 05:58:21

270 Views

This example demonstrates how do I use Marquee text in an 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.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity{    TextView textMarquee;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textMarquee = findViewById(R.id.textMarquee);       textMarquee.setText("Be the change that you ... Read More

How to get the difference between two dates in Android?

Azhar
Updated on 03-Jul-2020 05:59:08

3K+ Views

This example demonstrates how do I get the difference between two dates 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.TextView; import android.widget.Toast; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends AppCompatActivity{    TextView textView;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textView = findViewById(R.id.textView);     ... Read More

How to pass an arrayList to another activity using intents in Android?

Azhar
Updated on 03-Jul-2020 05:35:34

8K+ Views

This example demonstrates how do I pass an arrayList to another activity using intends 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 java.util.ArrayList; public class MainActivity extends AppCompatActivity{    Button button;    ArrayList numbers = new ArrayList();    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       ... Read More

How to control the height and width of the default alert dialog in android?

Azhar
Updated on 03-Jul-2020 05:36:17

5K+ Views

This example demonstrates how do I control the height and width of the default alert 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 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.Activity; import android.app.AlertDialog; import android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.WindowManager; import android.widget.Button; import android.widget.RelativeLayout;    public class MainActivity extends AppCompatActivity{       Button button;       RelativeLayout relativeLayout;       Context ... Read More

How can I dynamically set the position of view in android?

Azhar
Updated on 03-Jul-2020 05:37:34

3K+ 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 android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; public class MainActivity extends AppCompatActivity{    Button button;    TextView textView;    RelativeLayout relativeLayout;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       relativeLayout = ... Read More

Android How to draw a smooth line following my finger?

Azhar
Updated on 03-Jul-2020 05:41:07

590 Views

This example demonstrates how do I draw a smooth line following my finger 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.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; public class MainActivity extends AppCompatActivity implements View.OnTouchListener {    ImageView imageView;    Bitmap bitmap;    Canvas canvas;    Paint paint;    float downX = ... Read More

How to get current location latitude and longitude in Android?

Azhar
Updated on 30-Aug-2019 06:09:03

12K+ Views

This example demonstrates how do I get current location latitude and longitude 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.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.location.LocationManager; import android.provider.Settings; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    private static final ... Read More

How to change screen brightness programmatically in android?

Azhar
Updated on 02-Jul-2020 08:00:05

3K+ Views

This example demonstrates how do I change screen brightness programmatically 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.Context; import android.provider.Settings; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.SeekBar; public class MainActivity extends AppCompatActivity {    SeekBar lightBar;    Context context;    int brightness;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);   ... Read More

How to add a button dynamically in android?

Azhar
Updated on 02-Jul-2020 08:00:49

2K+ Views

This example demonstrates how do I add a button dynamically 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.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    RelativeLayout relativeLayout;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       relativeLayout = findViewById(R.id.relativeLayout);   ... Read More

Advertisements