Tuesday, September 2, 2014

How to create tutorial for Android Application

How to create tutorial for Android Application

This post about how to create application tutorial for android application.






TutorialActivity.class

import android.app.Activity;

import android.os.Bundle;

import android.support.v4.view.ViewPager;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageButton;

public class TutorialActivity extends Activity {

       int noofsize = 3;

       Button skipBtn;

       @Override
       protected void onCreate(Bundle savedInstanceState) {

              // TODO Auto-generated method stub

              super.onCreate(savedInstanceState);

              setContentView(R.layout.tutorial);

              TutorialAdapter adapter = new TutorialAdapter(TutorialActivity.this,

              noofsize);

              ViewPager myPager = (ViewPager) findViewById(R.id.reviewpager);

              skipBtn = (Button) findViewById(R.id.skip_btn);

              skipBtn.setOnClickListener(new OnClickListener() {

                     @Override
                     public void onClick(View v) {

                           TutorialActivity.this.finish();

                     }

              });

              myPager.setAdapter(adapter);

              myPager.setCurrentItem(0);

       }

}



MainActivity.class

public class MainActivity extends Activity {

       /**
        *
        * @iamvijayakumar
        */

       @Override
       protected void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              setContentView(R.layout.activity_main);

              Intent in = new Intent(MainActivity.this, TutorialActivity.class);

              startActivity(in);

       }

}




TutorialAdapte.class

package com.example.apptutorial;

import android.app.Activity;

import android.content.Context;

import android.os.Parcelable;

import android.support.v4.view.PagerAdapter;

import android.support.v4.view.ViewPager;

import android.view.LayoutInflater;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

/**
 *
 *
 *
 * @author iamvijayakumar
 *
 *
 */

public class TutorialAdapter extends PagerAdapter {

       int size;

       Activity act;

       View layout;

       ImageView pagenumber;

       Button click;

       int[] images = { R.drawable.step_one, R.drawable.step_two,
                     R.drawable.step_three };

       public TutorialAdapter(TutorialActivity tutorialActivity, int noofsize) {

              // TODO Auto-generated constructor stub

              size = noofsize;

              act = tutorialActivity;

       }

       @Override
       public int getCount() {

              // TODO Auto-generated method stub

              return size;

       }

       @Override
       public Object instantiateItem(View container, int position) {

              // TODO Auto-generated method stub

              LayoutInflater inflater = (LayoutInflater) act

              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

              layout = inflater.inflate(R.layout.tutorial_view, null);

              pagenumber = (ImageView) layout.findViewById(R.id.pagenumber);

              pagenumber.setBackgroundResource(images[position]);

              ((ViewPager) container).addView(layout, 0);

              return layout;

       }

       @Override
       public void destroyItem(View arg0, int arg1, Object arg2) {

              ((ViewPager) arg0).removeView((View) arg2);

       }

       @Override
       public boolean isViewFromObject(View arg0, Object arg1) {

              return arg0 == ((View) arg1);

       }

       @Override
       public Parcelable saveState() {

              return null;

       }

       // }

}

activity_main.xml

<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="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/textView1"
        android:text="Button 1" />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button1"
        android:layout_marginTop="24dp"
        android:text="Button 2" />

    <Button
        android:id="@+id/button3"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button2"
        android:layout_marginTop="52dp"
        android:text="Button 3" />

</RelativeLayout>

tutorial_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/pagenumber"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />

</RelativeLayout>

tutorial.xml

<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" >

    <android.support.v4.view.ViewPager
        android:id="@+id/reviewpager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    <Button
        android:id="@+id/skip_btn"
        android:layout_width="wrap_content"
        android:layout_height="30dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="16dp"
        android:background="@null"
        android:text="Skip"
        android:textColor="#ffffff"
        android:textStyle="bold" />

</RelativeLayout>










No comments:

Post a Comment

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...