Open top menu


In this tutorial implement the circle ImageView in Android.we will drow the design in xml using eclipse.
first, we will create a gradient class in Drawable folder my class is cercle_image.xml.





...................................................................................................................................................................
<?xml version="1.0" encoding="UTF-8" ?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="#000000" />
  <stroke android:width="3dp" android:color="#776da8" />
  <corners android:bottomRightRadius="100dp" android:bottomLeftRadius="100dp" android:topLeftRadius="100dp" android:topRightRadius="100dp" />
  <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
  </shape>





then you have set the class in ImageView in main class
..............................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     android:background="#000000">

    <ImageView
        android:id="@+id/image"
        android:layout_width="200dip"
        android:layout_height="200dip"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:scaleType="centerCrop"
        android:background="@drawable/cercle_image"
        android:src="@drawable/iconprofile" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="42dp"
        android:gravity="center"
        android:textSize="20sp"
        android:textStyle="bold"
        android:textColor="#ffffff"
        android:text="AndroidBeginner Tutorial point" />

</RelativeLayout>



Read more


In this Tutorial we will explain how to load web url in webview android widgets.
expailn below--
you can used webview, the webview class is an extends  android View class.
The WebView is allowed to display web page in your activity in android.

first you have to add  Internet permission in our application manifest.xml.

<uses-permission android:name="android.permission.INTERNET" />

then you have add WebView android wedgets in created activity_main.xml class.
.................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

</WebView>

then you have get WebView android wedgets  Id in created ActvityMain.java class.
.................................................................................................................................................................

package com.example.androidbeginnerpoint;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class AdvertiseActivity extends Activity {
  WebView webview;


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);


setContentView(R.layout.advertise);



webview=(WebView)findViewById(R.id.webview);

startWebView("androidbeginnerpoint.blogspot.in");



}
private void startWebView(String url) {
     
       
webview.setWebViewClient(new WebViewClient() {    
            ProgressDialog progressDialog;
       
           
            public boolean shouldOverrideUrlLoading(WebView view, String url) {            
                view.loadUrl(url);
                return true;
            }
     
            //Show loader on url load
            public void onLoadResource (WebView view, String url) {
                if (progressDialog == null) {
                 
                    progressDialog = new ProgressDialog(AdvertiseActivity.this);
                    progressDialog.setMessage("Loading...");
                    progressDialog.show();
                }
            }
            public void onPageFinished(WebView view, String url) {
                try{
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;
                }
                }catch(Exception exception){
                    exception.printStackTrace();
                }
            }
           
        });
       
     
webview.getSettings().setJavaScriptEnabled(true);
       
   
       
       
webview.loadUrl(url);
       
       
    }
   

   
    @Override
 
    public void onBackPressed() {
        if(webview.canGoBack()) {
        webview.goBack();
        } else {
                         super.onBackPressed();
        }
    }


}






Read more


In this Tutorial we will explain how to implement animated Numberpicker dialog with bounce.

first we will create animated xml class ,

res/anim/bounce.xml
..............................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator">
    <translate
        android:fromYDelta="-100%p"
        android:toYDelta="0"
        android:duration="2000"/>

</set>

res/anim/abc_slide_out_bottom.xml
..............................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>

<translate xmlns:android="http://schemas.android.com/apk/res/android"
           android:interpolator="@android:anim/accelerate_interpolator"
           android:fromYDelta="0" android:toYDelta="50%p"

           android:duration="@android:integer/config_mediumAnimTime"/> 

................................................................................................................................................................
res/value/styles
Then both anim class add in style theam,  how explain below
...................................................................................................................................................................

 <style name="DialogSlideAnim" parent="@android:style/Theme.Dialog">
        <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
    </style>
    
    <style name="DialogAnimation">
        <item name="android:windowEnterAnimation">@anim/bounces</item>
        <item name="android:windowExitAnimation">@anim/abc_slide_out_bottom</item>

</style>


Used this method in MainActivity.java
...................................................................................................................................................................

package com.example.androidtestcode;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.NumberPicker;
import android.widget.TextView;

public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener {
Context context;  
TextView tv;
Button button_decrement,button_increment;

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   setContentView(R.layout.activity_main);
   tv=(TextView)findViewById(R.id.textView1);
   tv.setText("1");
   button_decrement=(Button)findViewById(R.id.button_decrement);
   button_increment=(Button)findViewById(R.id.button_increment);
   context=this;

   button_decrement.setOnClickListener(new View.OnClickListener()
   {

       @Override
       public void onClick(View v)
       {
        String present_value_string = tv.getText().toString();
            if(present_value_string!=null)
            {
                int present_value_int = Integer.parseInt(present_value_string);
                if(present_value_int>1){
                present_value_int--;
                tv.setText(String.valueOf(present_value_int));
                }
            }          
       }
   });
   
 
}

public void show() {

final Dialog dialogbox = new Dialog(this,R.style.DialogSlideAnim);
dialogbox.setTitle("Set Number Of Tiffin");
dialogbox.setContentView(R.layout.pikerdiaog);
Button b1 = (Button) dialogbox.findViewById(R.id.button1);
Button b2 = (Button) dialogbox.findViewById(R.id.button2);
final NumberPicker nPicker = (NumberPicker) dialogbox
.findViewById(R.id.numberPicker1);
nPicker.setMaxValue(100);
nPicker.setMinValue(1);
nPicker.setWrapSelectorWheel(false);
nPicker.setOnValueChangedListener(this);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv.setText(String.valueOf(nPicker.getValue()));

dialogbox.dismiss();
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialogbox.dismiss();
}
});
dialogbox.show();

}

@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
Log.i("value is", "" + newVal);

}
}
...................................................................................................................................................................




Read more


In this Tutorial we will explain  Add and delet listview item.show below


main.xml
.............................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <EditText 
        android:id="@+id/txtItem"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:hint="@string/hintTxtItem"         
        />

    <Button 
        android:id="@+id/btnAdd"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/lblBtnAdd"
        android:layout_toRightOf="@id/txtItem"
        />

    <TextView 
        android:id="@android:id/empty"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/txtItem"
        android:text="@string/txtEmpty"
        android:gravity="center_horizontal"        
        />
<ListView
   android:id="@android:id/list"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"    
   android:layout_below="@id/txtItem"
   android:choiceMode="multipleChoice" >
</ListView>
<Button
   android:id="@+id/btnDel"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"    
   android:layout_alignParentBottom="true"
   android:text="@string/lblBtnDel" />

</RelativeLayout>

MainActivity.java
...........................................................................................................................................................


package com.android.beginner;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends ListActivity {

     
    ArrayList<String> list = new ArrayList<String>();

   
    ArrayAdapter<String> adapter;


     
    @Override
    public void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);
 
   setContentView(R.layout.main);
   
   Button btn = (Button) findViewById(R.id.btnAdd);
   
    
   Button btnDel = (Button) findViewById(R.id.btnDel);
 
   adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, list);
    
   OnClickListener listener = new OnClickListener() {
   
    public void onClick(View v) {
    // TODO Auto-generated method stub
    EditText edit = (EditText) findViewById(R.id.txtItem);
                 list.add(edit.getText().toString());
                 edit.setText("");
                 adapter.notifyDataSetChanged();
    }
   
   
   
                   
           };
           
    
   OnClickListener listenerDel = new OnClickListener() {
    public void onClick(View v) {
    // TODO Auto-generated method stub
    SparseBooleanArray checkedItemPositions = getListView().getCheckedItemPositions();
    int itemCount = getListView().getCount();
   
    for(int i=itemCount-1; i >= 0; i--){
    if(checkedItemPositions.get(i)){    
    adapter.remove(list.get(i));
    }
    }        
       adapter.notifyDataSetChanged();    
    }
     
   };            
   
   btn.setOnClickListener(listener);
   
   
   btnDel.setOnClickListener(listenerDel);    
   
   setListAdapter(adapter);
    }
}
Read more

In this tutorial we will explain how to create TabLayout in android.explain below.Tabhost show as multiple options menu .Now we created 3 Activity and 3 xml class.

main.xml

In this class create Tablayout android wigdets.
........................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>

Then create three activity xml class when open onclick tabview in android

songs_layout.xml
........................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

 
  <TextView android:text="SONGS HERE SCREEN"
  android:padding="15dip"
  android:textSize="18dip"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
</LinearLayout>

photos_layout.xml
.............................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

 
  <TextView android:text="PHOTOS HERE SCREEN"
  android:padding="15dip"
  android:textSize="18dip"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
 
</LinearLayout>

video_layout.xml
........................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

 
  <TextView android:text="VIDEOS HERE SCREEN"
  android:padding="15dip"
  android:textSize="18dip"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
</LinearLayout>


PhotosActivity.java
..............................................................................................................................................................
package com.example.androidtablayout;

import android.app.Activity;
import android.os.Bundle;

public class PhotosActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photos_layout);
    }
}

SongsActivity.java
..............................................................................................................................................................
package com.example.androidtablayout;

import android.app.Activity;
import android.os.Bundle;

public class SongsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.songs_layout);    }
}

VideosActivity.java
..............................................................................................................................................................
package com.example.androidtablayout;

import android.app.Activity;
import android.os.Bundle;

public class VideosActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videos_layout);
    }
}


AndroidTabLayoutActivity.java

In this class extends the TabActivity

...................................................................................................................................................................
package com.example.androidtablayout;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class AndroidTabLayoutActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TabHost tabHost = getTabHost();
        
        // Tab for Photos
        TabSpec photospec = tabHost.newTabSpec("Photos");
        photospec.setIndicator("Photos", getResources().getDrawable(R.drawable.photos_white));
        Intent photosIntent = new Intent(this, PhotosActivity.class);
        photospec.setContent(photosIntent);
        
        // Tab for Songs
        TabSpec songspec = tabHost.newTabSpec("Songs");
        // setting Title and Icon for the Tab
        songspec.setIndicator("Songs", getResources().getDrawable(R.drawable.songs_white));
        Intent songsIntent = new Intent(this, SongsActivity.class);
        songspec.setContent(songsIntent);
        
        // Tab for Videos
        TabSpec videospec = tabHost.newTabSpec("Videos");
        videospec.setIndicator("Videos", getResources().getDrawable(R.drawable.videos_white));
        Intent videosIntent = new Intent(this, VideosActivity.class);
        videospec.setContent(videosIntent);
        
        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
        tabHost.addTab(songspec); // Adding songs tab
        tabHost.addTab(videospec); // Adding videos tab
    }
}





Read more



In this tutorial explain how to used expendable listView in android.

main.xml

In this class drag and drop expendableListView widget.
..............................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#4079d6" >

            <ExpandableListView
                android:id="@+id/lvExp"
                android:layout_height="match_parent"
                android:layout_width="match_parent"/>

</LinearLayout>


list_group.xml

the another group item header xml class.
.................................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp"
    android:background="#000000">


    <TextView
        android:id="@+id/lblListHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
        android:textSize="17dp"
        android:textColor="#f9f93d" />

</LinearLayout>



list_item.xml

create a another listview item xml class, child items.
.................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblListItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="17dip"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />

</LinearLayout>


ExpendableAdapter.java

we will create a expendableAdapter class and extends BaseExpandableListAdapter  adapter

getGroupView()  the Method set the required group header.
getChildView() the method set listView item.

............................................................................................................................................................

 package com.example.androidbeginner;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ExpendableAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<String>> _listDataChild;

    public ExpendableAdapter(Context context, List<String> listDataHeader,
            HashMap<String, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }

public Object getChild(int groupPosition, int childPosititon) {
// TODO Auto-generated method stub
return _listDataChild.get(this._listDataHeader.get(groupPosition))
        .get(childPosititon);
}

public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}

public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);

        txtListChild.setText(childText);
        return convertView;
}

public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
        .size();
}

public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return this._listDataHeader.get(groupPosition);
}

public int getGroupCount() {
// TODO Auto-generated method stub
return this._listDataHeader.size();
}

public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}

public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
       if (convertView == null) {
           LayoutInflater infalInflater = (LayoutInflater) this._context
                   .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           convertView = infalInflater.inflate(R.layout.list_group, null);
       }

       TextView lblListHeader = (TextView) convertView
               .findViewById(R.id.lblListHeader);
       lblListHeader.setTypeface(null, Typeface.BOLD);
       lblListHeader.setText(headerTitle);

       return convertView;
}

public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}

   
}


MainActivity.java

.........................................................................................................................................................


package com.example.androidbeginner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.Toast;

public class MainActivity extends Activity {

    ExpendableAdapter listAdapter;
    ExpandableListView expListView;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // get the listview
        expListView = (ExpandableListView) findViewById(R.id.lvExp);

        // preparing list data
        prepareListData();

        listAdapter = new ExpendableAdapter(this, listDataHeader, listDataChild);

        // setting list adapter
        expListView.setAdapter(listAdapter);
        expListView.setOnGroupClickListener(new OnGroupClickListener() {

public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// TODO Auto-generated method stub
return false;
}
});

        expListView.setOnGroupExpandListener(new OnGroupExpandListener() {

public void onGroupExpand(int groupPosition) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
                        listDataHeader.get(groupPosition) + " Expanded",
                        Toast.LENGTH_SHORT).show();
}
});
        expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {

public void onGroupCollapse(int groupPosition) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),
                       listDataHeader.get(groupPosition) + " Collapsed",
                       Toast.LENGTH_SHORT).show();
}
});
        expListView.setOnChildClickListener(new OnChildClickListener() {

public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
 Toast.makeText(
                       getApplicationContext(),
                       listDataHeader.get(groupPosition)
                               + " : "
                               + listDataChild.get(
                                       listDataHeader.get(groupPosition)).get(
                                       childPosition), Toast.LENGTH_SHORT)
                       .show();
return false;
}
});
     
     
    }

    /*
     * Preparing the list data
     */
    private void prepareListData() {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding child data
        listDataHeader.add("Top Most Used Color Name");
        listDataHeader.add("Planet Order List");
        listDataHeader.add("Coming Soon..");

        // Adding child data
        List<String> ColorName = new ArrayList<String>();
        ColorName.add("RED");
        ColorName.add("BLUE");
        ColorName.add("YELLOW");
        ColorName.add("GREEN");
        ColorName.add("PINK");
        ColorName.add("BLACK");
        ColorName.add("WHITE");

        List<String> nowShowing = new ArrayList<String>();
        nowShowing.add(" Sun");
        nowShowing.add("Mercury");
        nowShowing.add("Earth");
        nowShowing.add("Mars");
        nowShowing.add("Jupiter");    
        nowShowing.add(" Saturn");
        nowShowing.add("Uranus");
        nowShowing.add("Neptune");
       

        List<String> comingSoon = new ArrayList<String>();
        comingSoon.add("Aries - Your identity ");
        comingSoon.add("Taurus - Your personal resources");
        comingSoon.add("Gemini - Your communicative skills ");
        comingSoon.add("Cancer - Your family and home");
        comingSoon.add("Leo - Your interests and likings ");
     
        comingSoon.add("Virgo - Your day to day works ");
        comingSoon.add("Libra - Your partners in life");
        comingSoon.add("Scorpio - that which cannot be controlled by you  ");
        comingSoon.add("Sagittarius - your travels");
        comingSoon.add("Capricorn - your career and social status ");
     
        comingSoon.add("Aquarius - Your ideals in life ");
        comingSoon.add("Pisces - Your shortcomings ");
     

        listDataChild.put(listDataHeader.get(0), ColorName); // Header, Child data
        listDataChild.put(listDataHeader.get(1), nowShowing);
        listDataChild.put(listDataHeader.get(2), comingSoon);
    }
}

Read more



In this tutorial we will explain how to used Time Picker android widgets ,below explain


main.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:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity" >
 
   <TextView
      android:id="@+id/textView2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:text="@string/time_pick"
      android:textAppearance="?android:attr/textAppearanceMedium" />
   
   <Button
      android:id="@+id/set_button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="180dp"
      android:onClick="setTime"
      android:text="@string/time_save" />
   
   <TimePicker
      android:id="@+id/timePicker1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/set_button"
      android:layout_centerHorizontal="true"
      android:layout_marginBottom="24dp" />
   
   <TextView
      android:id="@+id/textView3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/timePicker1"
      android:layout_alignTop="@+id/set_button"
      android:layout_marginTop="67dp"
      android:text="@string/time_current"
      android:textAppearance="?android:attr/textAppearanceMedium" />
   
   <TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/textView3"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="50dp"
      android:text="@string/time_selected"
      android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

string.xml

............................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, AndroidBeginner!</string>
    <string name="app_name">AndroidBeginner_testcode</string>
    <string name="action_settings">Settings</string>
   <string name="time_picker_example">Time Picker Example</string>
   <string name="time_pick">PICK TIME VIA PRESS SAVE BUTTON</string>
   <string name="time_save">OK</string>
   <string name="time_selected"></string>
   <string name="time_current">The Time is-></string>

</resources>


MainActivity.java

........................................................................................................................................................


package com.example.androidbeginner;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity extends Activity {
private TimePicker TimePicker;
  private TextView TextTime;
  private Calendar calendar;
  private String format = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getActionBar().setTitle("Date Picker Test");

 setContentView(R.layout.main);
 TimePicker = (TimePicker)findViewById(R.id.timePicker1);
 TextTime = (TextView) findViewById(R.id.textView1);
     calendar = Calendar.getInstance();
   
     int hour = calendar.get(Calendar.HOUR_OF_DAY);
     int min = calendar.get(Calendar.MINUTE);
     showTime(hour, min);
  }

  public void setTime(View view) {
     int hour = TimePicker.getCurrentHour();
     int min = TimePicker.getCurrentMinute();
     showTime(hour, min);
  }

  public void showTime(int hour, int min) {
     if (hour == 0) {
        hour += 12;
        format = "AM";
     }
     else if (hour == 12) {
        format = "PM";
     } else if (hour > 12) {
        hour -= 12;
        format = "PM";
     } else {
        format = "AM";
     }
     TextTime.setText(new StringBuilder().append(hour).append(" : ").append(min)
     .append(" ").append(format));
  }


}
Read more




In this tutorial implement the DatePicker ,explain below some code.

In this tutorial create the DatepickerDialog, the dialog is Override method

onCreateDialog(int id)

in this method set the date picker id



activity_main.xml

......................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Android Beginner tutorials"
        android:textSize="12dp" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
       
          >

        <EditText
            android:id="@+id/editText_dateinvoice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="15dp"
            android:ems="10"
         
            android:inputType="date"
            android:textStyle="italic" />

        <ImageButton
            android:id="@+id/imageButton_dateinvpice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_alignBottom="@+id/editText_dateinvoice"
             android:layout_toRightOf="@+id/editText_dateinvoice"
            android:src="@drawable/calendaer"
            android:contentDescription="@null" />

    </RelativeLayout>

</LinearLayout>



MainActivity.java
..................................................................................................................................................
package com.androidbeginnerpoint.testapplication;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;

public class MainActivity extends Activity implements OnClickListener {

private int day;
private int month;
private int year;
private ImageButton btn_ofinvoice;
private Calendar cal;
private EditText edtdate_ofinvoice;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn_ofinvoice=(ImageButton)findViewById(R.id.imageButton_dateinvpice);
edtdate_ofinvoice=(EditText)findViewById(R.id.editText_dateinvoice);
edtdate_ofinvoice.setEnabled(false); //disable edittext

cal = Calendar.getInstance();
day = cal.get(Calendar.DAY_OF_MONTH);
month = cal.get(Calendar.MONTH);
year = cal.get(Calendar.YEAR);

btn_ofinvoice.setOnClickListener(this);
}

@Override
public void onClick(View v) {            
showDialog(0);
}

@Override
@Deprecated
protected Dialog onCreateDialog(int id) {
return new DatePickerDialog(this, datePickerListener, year, month, day);
}

private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
edtdate_ofinvoice.setText(selectedDay + " / " + (selectedMonth + 1) + " / "
+ selectedYear);
}
};

}
Read more



In this tutorial we will explain how to detect Internet connection. the internet connection we will find before  call http request and json etc , in our android application.

first you have declare internet accuses permission in Manifest.xml.



 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Internet_Status.java
..........................................................................................................................................................

package com.androidbeginnerpoint.testapplication;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Internet_Status {
   
    private Context _context;
   
    public Internet_Status(Context context){
        this._context = context;
    }

    public boolean isConnectingToInternet(){
        ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
          if (connectivity != null)
          {
              NetworkInfo[] info = connectivity.getAllNetworkInfo();
              if (info != null)
                  for (int i = 0; i < info.length; i++)
                      if (info[i].getState() == NetworkInfo.State.CONNECTED)
                      {
                          return true;
                      }

          }
          return false;
    }
}


MainActivity.java

in this class create a Internet_ststus.java instance and find is return value.
.............................................................................................................................................................

package com.androidbeginnerpoint.testapplication;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Toast;

@SuppressLint("NewApi")
public class MainActivity extends Activity {
boolean isInternet_connect= false;
 
// creating connection detector class instance
Internet_Status detect_internet=new Internet_Status(getApplication());
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle("Internetconnection tutorial");
setContentView(R.layout.activity_main);
isInternet_connect=detect_internet.isConnectingToInternet();
setContentView(R.layout.activity_main);
// check for Internet status
if(isInternet_connect) {
Toast.makeText(getApplication(), "Internet connection is persent", Toast.LENGTH_LONG).show();
AlertDialogBox("your internet connection is persent !");
  }
else {
AlertDialogBox("your internet connection is Not persent !");
}
 
}
public  void AlertDialogBox(String str) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("LOOK UP");
builder.setMessage(str);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});

builder.create().show();
}
}
Read more