Expandable ListView in Android

A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view. main_activity.xml <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”    xmlns:app=”http://schemas.android.com/apk/res-auto”    xmlns:tools=”http://schemas.android.com/tools”    android:layout_width=”match_parent”    android:layout_height=”match_parent”    …

Expandable ListView in Android Read More »

Android RecyclerView Tutorial

Step 1:build.gradle compile ‘com.android.support:cardview-v7:26+’ compile ‘com.android.support:recyclerview-v7:26.+’ Step 2:main_activity.xml <?xml version=“1.0” encoding=“utf-8”?>   <RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”     xmlns:app=“http://schemas.android.com/apk/res-auto”     xmlns:tools=“http://schemas.android.com/tools”     android:layout_width=“match_parent”     android:layout_height=“match_parent”     tools:context=“csdevbin.arham.recyclerviewdemo.MainActivity”>     <android.support.v7.widget.RecyclerView         android:id=“@+id/my_recycler_view”         android:layout_width=“match_parent”         android:layout_height=“match_parent”         android:scrollbars=“vertical” /> </RelativeLayout> Step 3: card.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”  xmlns:card_view=”http://schemas.android.com/apk/res-auto”     xmlns:tools=”http://schemas.android.com/tools”     android:layout_width=”match_parent”     android:layout_height=”wrap_content”>     <!– A CardView that contains a …

Android RecyclerView Tutorial Read More »

Android Fragment Lifecycle

Here is the list of methods which you can to override in your fragment class − onAttach()The fragment instance is associated with an activity instance.The fragment and the activity is not fully initialized. Typically you get in this method a reference to the activity which uses the fragment for further initialization work. onCreate() The system calls …

Android Fragment Lifecycle Read More »

JSON Example

JSON :- JavaScript Object Notation It contains key/value pairs Key-> Strings Values:->JSON {}   :-> JSON Object []    :-> JSON array Syntax : {“employees”:[    {“firstName”:“John”, “lastName”:“Doe”},    {“firstName”:“Anna”, “lastName”:“Smith”},    {“firstName”:“Peter”, “lastName”:“Jones”}]} package csdevbin.json; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; import org.json.JSONObject; public class MainActivity extends AppCompatActivity {     public static final String JSON_STRING = “{“employee“:{“name“:“John“,“salary“:6000}}”;     @Override     …

JSON Example Read More »

Grid View

GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a ListAdapter. Project Structure: 1.MainActivity.java2.ImageAdapter.java3.main_activity.xml4.Save the image files into the project’s res/drawable/ directory.  (Download) main_activity.xml <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”    xmlns:tools=”http://schemas.android.com/tools”    android:id=”@+id/activity_main”    android:layout_width=”match_parent”    android:layout_height=”match_parent”    android:paddingBottom=”@dimen/activity_vertical_margin”    android:paddingLeft=”@dimen/activity_horizontal_margin”    android:paddingRight=”@dimen/activity_horizontal_margin”    android:paddingTop=”@dimen/activity_vertical_margin”    tools:context=”com.blogspot.csdevbin.listexample.MainActivity”>    <GridView        android:id=”@+id/gridview”        android:layout_width=”match_parent        android:layout_height=”match_parent”         android:columnWidth=”90dp”        android:numColumns=”auto_fit”        android:verticalSpacing=”10dp”        android:horizontalSpacing=”10dp”        android:stretchMode=”columnWidth”        …

Grid View Read More »

SharedPreferences 2

MainActivity.java package com.blogspot.csdevbin.sharedpreferences; import android.content.Context; import android.content.SharedPreferences; import 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; import android.widget.Toast; public class MainActivity extends AppCompatActivity {     EditText food,shopping,fuel,telephone;     TextView previousExpense;     SharedPreferences sharedPreferences;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          food = (EditText)findViewById(R.id.etfood);          shopping = …

SharedPreferences 2 Read More »

Button Example 2

MainActivity.java package com.blogspot.csdevbin.mynewpractice; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity {     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         B1();     }     private void B1() {         Button b1 = (Button) findViewById(R.id.button1);         b1.setOnClickListener(new View.OnClickListener() {             @Override             public void …

Button Example 2 Read More »

Send Email Example

MainActivity.java package com.blogspot.csdevbin.sendingemail; import android.content.Intent; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity {     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         Button startBtn = (Button) findViewById(R.id.sendEmail);         startBtn.setOnClickListener(new View.OnClickListener() {             public void onClick(View view) { …

Send Email Example Read More »

Fragment Example 1

MainActivity.xml <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”     xmlns:tools=“http://schemas.android.com/tools”     android:id=“@+id/LinearLayout1”     android:layout_width=“match_parent”     android:layout_height=“match_parent”     android:orientation=“vertical”     tools:context=“.MainActivity” >     <TextView         android:id=“@+id/textView1”         android:layout_width=“wrap_content”         android:layout_height=“wrap_content”         android:text=“Large Text”         android:textAppearance=“?android:attr/textAppearanceLarge” />     <Button         android:id=“@+id/button1”         android:layout_width=“wrap_content”         android:layout_height=“wrap_content”         android:text=“Button” />     <fragment         android:id=“@+id/frag”         android:layout_width=“match_parent”         android:layout_height=“match_parent”         class=“com.blogspot.csdevbin.fragment.MainActivity$SSFFragment” /> </LinearLayout> hellofrag.xml <TextView    …

Fragment Example 1 Read More »