Found 1631 Articles for Android

How to parse JSON Objects on Android?

Azhar
Updated on 03-Jul-2020 06:00:38

524 Views

This example demonstrates how to parse JSON Objects on 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 dependency to Gradle Scripts ⇒ build.gradle and do syncapply plugin: 'com.android.application' android {    compileSdkVersion 28    defaultConfig {       applicationId "com.example.sample"       minSdkVersion 21       targetSdkVersion 28       versionCode 1       versionName "1.0"       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }    buildTypes {       release { ... Read More

How to make an ImageView with rounded corners on Android App?

Azhar
Updated on 03-Jul-2020 06:01:17

6K+ Views

This example demonstrates how to make an ImageView with rounded corners on 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.example.sample; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Shader; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) ... Read More

How to parse JSON on Android?

Azhar
Updated on 03-Jul-2020 06:01:52

217 Views

This example demonstrates how to parse JSON 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.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import org.json.JSONException; import org.json.JSONObject; public class MainActivity extends AppCompatActivity {    String JSON_STRING="{\"employee\":{\"name\":\"adolf hitler\", \"salary\":65000}}";    String name, salary;    TextView employeeName, employeeSalary;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);     ... Read More

How to make an android spinner with initial default text?

Azhar
Updated on 03-Jul-2020 06:03:10

7K+ Views

This example demonstrates how do I make an android spinner with initial default text 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.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity {    Spinner spinner;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState); ... Read More

What is Context on Android?

Azhar
Updated on 03-Jul-2020 06:09:18

6K+ Views

Definitionit's the context of current state of the application/object. It lets newly-created objects understand what has been going on. Typically, you call it to get information regarding another part of your program (activity and package/application). In the below program you will see that we have created a textView dynamically and passed context. This context is used to get the information about the environment.This example demonstrates how do I display context in an android textView.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 ... Read More

How can I disable/enable GPS programmatically in android?

Azhar
Updated on 03-Jul-2020 06:10:08

324 Views

This example demonstrates how do I disable/enable GPS 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.content.Intent; import android.location.LocationManager; import android.provider.Settings; 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 {    TextView textView;    Button buttonGps;    Context context;    LocationManager locationManager ;    boolean GpsStatus ;    @Override    public void ... Read More

How to add a line break in an android textView?

Azhar
Updated on 03-Jul-2020 06:22:30

6K+ Views

This example demonstrates how do I add a line break in an android textView.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.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; 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);       textView.setTextColor(Color.RED);    } ... Read More

How to pass drawable between activities in android?

Azhar
Updated on 03-Jul-2020 06:23:20

700 Views

This example demonstrates how do I pass drawable between activities 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 {    Button button;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       button = findViewById(R.id.button);       button.setOnClickListener(new View.OnClickListener() { ... Read More

How to change android overflow menu icon programmatically?

Azhar
Updated on 03-Jul-2020 06:24:42

2K+ Views

This example demonstrates how do I change android overflow menu icon 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 android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    Toolbar toolbar;    @Override    public void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       toolbar ... Read More

How to convert ISO 8601 string to Date/time object in Android?

Azhar
Updated on 03-Jul-2020 05:53:39

1K+ Views

This example demonstrates how do I convert ISO 8601 string to date/time object 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 java.text.ParseException; 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

Advertisements