Use XMLPullParser to Parse XML in Android

Azhar
Updated on 02-Jul-2020 07:21:53

1K+ Views

This example demonstrates how do I XMLPullParser 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 – Right click in the res/layout and create a layout resource file(row.xml) and add the following code −             Step 4 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; import java.io.IOException; import java.io.InputStream; ... Read More

Display ListView in Android Alert Dialog

Azhar
Updated on 02-Jul-2020 07:19:55

2K+ Views

This example demonstrates how do I display a listView in an android aler dialog.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.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends AppCompatActivity {    String[] names = {"India", "Brazil", "Argentina",       "Portugal", "France", "England", "Italy"};    ArrayAdapter adapter;    ListView listView;    @Override    protected ... Read More

Create GridView Layout in an Android App

Azhar
Updated on 02-Jul-2020 07:19:21

676 Views

This example demonstrates how do I gridView layout 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 – Open build.gradle(Module: app) and add the following dependency −implementation 'com.android.support:gridlayout-v7:28.0.0'Step 4 − 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.GridView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    GridView gridView;    String[] numberInWords = {"One", "Two", "Three", "Four", "Five", "Six", "Seven", ... Read More

Get Value of EditText Field in Android

Azhar
Updated on 02-Jul-2020 07:18:42

643 Views

This example demonstrates how do I get the value of a editText filed 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.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    Button button;    EditText editText;    String string;    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) ... Read More

Parse JSONArray in Android App

Azhar
Updated on 02-Jul-2020 07:18:02

219 Views

This example demonstrates how do I parse JSONArray 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.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       textView = findViewById(R.id.textView);     ... Read More

Hide Soft Keyboard on Android After Clicking Outside EditText

Azhar
Updated on 02-Jul-2020 07:17:03

3K+ Views

This example demonstrates how do I hide soft keyboard on android after clicking outside edittext.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.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    EditText editText;    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       ... Read More

Add Custom Adapter for ListView in Android

Azhar
Updated on 02-Jul-2020 07:15:55

3K+ Views

This example demonstrates how do I add custom adapter for my listView 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.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ListView; import java.util.ArrayList; public class MainActivity extends AppCompatActivity {    ListView listView;    ArrayList arrayList = new ArrayList();    MyAdapter adapter;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main); ... Read More

Find Serial Number of Android Device

Azhar
Updated on 02-Jul-2020 07:15:18

866 Views

This example demonstrates how do I find serial number of 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 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.pm.PackageManager; import android.support.v4.content.ContextCompat; import android.os.Build; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.telephony.TelephonyManager; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    public static final int REQUEST_CODE_PHONE_STATE_READ = 100;    private int checkedPermission = PackageManager.PERMISSION_DENIED;    TelephonyManager ... Read More

Calculate the Sum of Square of First N Natural Numbers in PHP

AmitDiwan
Updated on 02-Jul-2020 07:14:49

674 Views

To calculate the sum of square of first n natural numbers in PHP, the code is as follows −Example Live DemoOutputThe sum of square of first 5 natural numbers is 125A function named ‘sum_of_squares’ is defined that takes the limit up to which square of natural number needs to be found. In this function, a sum value is initialized to 0. A ‘for’ loop is run over the elements ranging from 1 to the limit. Every time, to the ‘sum’ variable, square of the iterated value is added. When the control reaches the end, the value of sum is returned as ... Read More

Draw Text on Image in Android

Azhar
Updated on 02-Jul-2020 07:14:34

4K+ Views

This example demonstrates how do I draw text on imagein 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.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; 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 = findViewById(R.id.text);       textView.setText("This ... Read More

Advertisements