Area of a N-sided Regular Polygon with Given Radius

Arnab Chakraborty
Updated on 01-Aug-2019 07:30:04

286 Views

Here we will see how to get the area of an n-sided regular polygon whose radius is given. Here the radius is the distance from the center of any vertex. To solve this problem, we have drawn one perpendicular from the center to one side. Let each side is of length ‘a’. The perpendicular is dividing the side into two parts. The length of each part is a/2. The perpendicular and one radius is making an angle x. Let the length of the radius is h.Here we can see that the polygon is divided into N equal triangles. So for ... Read More

Area of a Leaf Inside a Square

Arnab Chakraborty
Updated on 01-Aug-2019 07:26:47

1K+ Views

Here we will see how to get the area of a leaf-like below, which is present inside the square ABCD. Each side of the square is of length ‘a’.The leaf has two equal parts. Area of each part is said p, now −And the area of the full leaf is 2p.Example#include using namespace std; float leafArea(float a){    return (a * a * (3.1415/2 - 1)); } int main() {    float square_side = 7.0f;    cout

Set 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

Change Screen Orientation Programmatically in Android

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

2K+ 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 Static Variables in Android Studio

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

684 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

Load ImageView by URL on Android Using Picasso

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

715 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

Get 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

Call onDestroy Activity in Android App

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

1K+ 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

Change Color of Button in Android When Clicked

Azhar
Updated on 01-Aug-2019 07:15:44

5K+ Views

This example demonstrates about How do I change the color of Button in Android when clicked.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; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       final Button button = findViewById(R.id.button);     ... Read More

Detect Airplane Mode Status in Android

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

1K+ Views

This example demonstrates about How to detect airplane mode is on or off in AndroidStep 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 app.com.sample; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.os.Bundle; import android.provider.Settings; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textView ... Read More

Advertisements